Course 1 / Lecture 12

How to develop a softphone in C#

How to create a call assistant

Download: call-assistant.zip

Ozeki VoIP SIP SDK provides professional technology to create a call assistant application. With the help of the call assistant, work is much easier for the agents who receive the calls. They can see who the caller is and they can answer, reject, hold/unhold or transfer the incoming calls.

This example will show you how to create a call assistant application with these basic funcionalities.

What knowledge would you need?

To fully understand this guide, you might need to study the following chapters first:

  • SIP registration: you can learn how to begin softphone developing and how to be able to register to a pbx with a sip account.
    Learn more...
  • Managing media handlers: you can find here examples and a simple guide about how to be able to use, connect and manage different media handlers, and how can you attach them to calls.
    Learn more...
  • Making and accepting calls: from this guide you can learn how can your softphone make and accept calls, and handle the calls' states.
    Learn more...
  • Controlling the call: you can learn how to control calls, for example: how to transfer them to another party.
    Learn more...

What is a call assistant?

The main role of the call assistant is to make the work of your employees easier. Eventually it is a collection of useful applications. The present example introduces the call assistant softphone application with a simple Graphical User Interface (GUI). This sample program can handle not only incoming but also outgoing calls.
This example checks for the incoming caller in the database, and if the caller can be found in the database, the data of the caller will be shown (username, full name, country, note).
Besides this, the present sample capable of rejecting, holding/unholding and transferring the call.

Call assistant source code analysis in C#

In this present example, the application uses a local database provided by Visual Studio 2019. Of course, you can switch from this database to any other database. If you want to create a local database you should right click on the project then choose Add, New Item, and here select the Service-based Database option from the list. Now in this example, the name of the database will be UserInfoContainer.mdf. After that you can create the UserInfos table. The data of the users (username, real name, country, note) are stored in this table.

The sample example project contains 4 classes: UserInfo.cs, DatabaseManager.cs, MainForm.cs and Program.cs.

The UserInfo class is responsible for the UserInfo object that handles the data of the users.

	class UserInfo
    {
        public UserInfo(string userName, string realName, string country, string note)
        {
            UserName = userName;
            RealName = realName;
            Country = country;
            Note = note;
        }

        public string UserName { get; private set; }
        public string RealName { get; private set; }
        public string Country { get; private set; }
        public string Note { get; private set; }
    }

The Program.cs class runs the example. This is the main entry point for the application.

You can access the local database with the help of the DatabaseManager class. For the access, you need a connectionString, the name of which can be found in the name property of the App.config files. The constructor of the DatabaseManager class creates this connectionString variable and the SqlConnection object. Then it calls the OpenConnection() method in order to connect to the local database.

		string _connectionString;
        SqlConnection _connection;

        public DatabaseManager()
        {
            _connectionString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString();
            _connection = new SqlConnection(_connectionString);

            OpenConnection();
            TestAdder();
        }

        void OpenConnection()
        {
            try
            {
                _connection.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Furthermore, it calls the TestAdder() method. As a result, a few test users will be added to the database with the help of a simple SQL INSERT command.

The DatabaseManager class contains a GetOtherPartyInfos() method, which reads the data of the users in the local database. This happens with a simple SQL SELECT query, where the username is the same as the caller username. If the caller username is not in the database, the call assistant shows unknown (N/A) information.

	public UserInfo GetOtherPartyInfos(string userName)
        {
            UserInfo userInfo;

            using (var command = _connection.CreateCommand())
            {
                command.CommandText = "SELECT * FROM UserInfos WHERE Username = '" + userName + "'";

                using (var reader = command.ExecuteReader())
                {
                    if (reader.HasRows)
                    {
                        reader.Read();
                        var realName = reader["RealName"].ToString();
                        var country = reader["Country"].ToString();
                        var note = reader["Note"].ToString();

                        userInfo = new UserInfo(userName, realName, country, note);

                        return userInfo;
                    }
                }
            }

            userInfo = new UserInfo("userName", "N/A", "N/A", "N/A");
            return userInfo;
        }

The MainForm.cs class contains the MS Windows Forms GUI (Figure 1), and the whole logic of the sample program (except the database handling and the user info representation).

call assistant example programs gui
Figure 1 - Call assistant example programs GUI

In the MainForm class, the SIP registration and the handling of calls take place. In addition, all functionalities (answer, call, hold, unhold, transfer) are implemented here. These are similar to the ones in the case of console sample programs. If you wish to learn more about these functionalities and the way they operate, you can find further information on the following pages:

Besides, there is a detailed tutorial video series on how to build a softphone with GUI. The first episode of this series is about SIP registration.

Conclusion

As you could see, to create a call assistant applications with Ozeki VoIP SIP SDK is really simple, and you also have several options to configure that. As you are now familiar with all the terms concerning this topic, now it is time to take a step further and explore what other extraordinary solution Ozeki VoIP SIP SDK can provide to you.

Related Pages

More information