Integrating Telegram and Avaya

When a business problem arose to create a high-speed mechanism for notifying a user about events in the Contact Center (queue overflow) and a telephone exchange (notification of missed calls), the thought of Telegram came to mind.

In fact, in this situation Telegram, this is just one of the possible options. Can be done via SMS. You can do the trite by email, and then he will come to the user on the mobile and he will get out a server Push. Or do it directly on the application on your mobile so that Push is obtained directly from it.

But each method has its drawbacks. For SMS you have to pay. Email clogs the user with a constant arrival and the user stops responding. A separate application on the phone must be made for each platform, install and organize the registration of tokens on the company's internal servers. The solution with the telegram of these minuses is deprived, although the application must of course be installed on the mobile, desktop or elsewhere. However, Telegram also has a minus. This is our esteemed Roskomnadzor, who does not like him very much. This brings some extra piquancy to the implementation.

So.

Inspired by this and that, I set to work.

To start, I created a bot in BotFather

image

Then you should work directly with the API.

Having found this worthy publication, I turned to Hetzner and organized my http proxy to work with api for only 3 euros per month in German territory.

The next required step is to create a group that will include your users and the newly created chat bot itself. This is spam protection. That is what Viber lacks for example.

image

Next you need to know the numbers of the required users.
To do this, each user must drop a message in the chat. In general, it is arbitrary. But we use for example for this purpose the phrase register and a certain number. The number will be an identifier for the PBX.

image

Now let's turn to the API.

Using the newly created proxy, we make the following request directly from the proxy shell. If you have already switched your browser to work with it, then you can directly from the browser.

root@ubuntu-dsenash ~ # wget https://api.telegram.org/bot553:AAGrXfKHw/getUpdates --2018-06-21 11:11:25-- https://api.telegram.org/bot553:AAGrXfKHw/getUpdates Resolving api.telegram.org (api.telegram.org)... 149.154.167.220, 2001:67c:4e8:f004::9 Connecting to api.telegram.org (api.telegram.org)|149.154.167.220|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 370 [application/json] Saving to: 'getUpdates' getUpdates 100%[==================================================================================>] 370 --.-KB/s in 0s 2018-06-21 11:11:25 (14.1 MB/s) - 'getUpdates' saved [370/370] root@ubuntu-dsenash ~ # cat getUpdates {"ok":true,"result":[{"update_id":90770, "message":{"message_id":43,"from":{"id":3918,"is_bot":false,"first_name":"Dmitry","last_name":"Senashenko","language_code":"ru"},"chat":{"id":3918,"first_name":"Dmitry","last_name":"Senashenko","type":"private"},"date":1529572218,"text":"/register 1000","entities":[{"offset":0,"length":9,"type":"bot_command"}]}}]}root@ubuntu-dsenash ~ # 

Instead of "553: AAGrXfKHw" indicates what you received from BotFather.

In response, we look for the user ID of the user who left the register message.
In the text above we see the message itself: "/ register 1000"
And the desired user ID: "id": 3918 "
Instead of xxxxx, of course there are real numbers.

Now you can check the operation of the bot and API directly from the shell or from your browser with the following request:

api.telegram.org/bot553 : AAGrXfKHw / sendMessage? text = Your_queue_is_over loaded

Where bot553: AAGrXfKHw is the bot number and key obtained from BotFather, and 3918xxxxxx is the user number obtained from the previous step.
You can use Russian in the text, but spaces must be replaced with% 20.

As a result of this command, the message was received in Telegram on the desktop and on the mobile phone at the same time.

image
image

The browser returned the following response:
image
So api works. Now go to the integration with the Avaya telephone exchange. For this purpose, I will use the Avaya Aura Experience Portal 7.1 product. It is used to organize IVR in the Avaya ecosystem and is a fully soft virtualized intellectual service platform. Its important feature is the ability to insert Java code, which is what we need to integrate with Telegram. I will not create advertising, but in my opinion this is one of the best Avaya products and you can write really amazing things on it. For example, voice control of the kettle or more serious Transcribing a conversation on the fly .

This IVR system is certainly very expensive, but there are features. It is licensed by ports. Since we plan to use it extremely briefly, one port will be enough. And one port has a fairly low cost. And with virtualization, the system only requires 2 Core / 4GB RAM / 60GB HDD. In general, it can be installed on almost any laptop or desktop. Well, like a cherry on a cake - this product has a trial mode that allows you to use it for free for 30 days.

To accomplish the task, we need to organize a call to the IVR on an event in the telephone station and further configure it so that it sends the appropriate event using the newly created API.

If we consider the task of notifying the supervisor of the excess of the number of calls in the queue to the Contact Center, then the telephone station will need to modify the main vector and create an additional one.

CALL VECTOR

Number: 5 Name: Vector for Skill 5

01 goto step 5 if calls-queued in skill 5 pri m> 5
02 queue-to skill 5 pri m
03 wait-time 30 secs hearing silence
04 goto step 3 if unconditionally
05 route-to number 1214 with cov n if unconditionally
06 goto step 2 if unconditionally

This vector immediately before placing the call in the queue checks the number of calls in the queue. If it exceeds 5, then the call goes to step 5, where it is transferred to the number 1214. This number is routed to the IVR.

In the condition in step 1, you can check a huge number of parameters that are indicative of the load in the Contact Center. For example, EWT, the number of available agents, the number of agents entered in the system, the number of calls in the queue, the level of service, etc. and if one indicator or another is exceeded, forward the call to the IVR.

The application in the IVR will start sending the message to the Telegram and immediately transfer the call back to the Contact Center on a similar vector, only without step 1 and 5.

The delay time of such a call for processing will be about 100 milliseconds, which is absolutely irrelevant for the caller.

The second vector will look like this:

CALL VECTOR

Number: 6 Name: Skill 5 Direct

01 queue-to skill 5 pri m
02 wait-time 30 secs hearing silence
03 goto step 2 if unconditionally

So the event call is redirected to IVR. Let's turn to the development of the application on it.

Applications for the Avaya Aura Experience Portal are developed in Eclipse with the Orchestration Designer plugin installed. This allows you to transfer development for unqualified users to the Drag & Drop mode of moving squares and arrows without diving into Java code.

Well, qualified users can already do interspersing Java code. Then the application is assembled as a servlet and is deployed to Tomcat, where IVR refers when receiving a call.

The application is as follows:

image
The call goes to the AppRoot node, then the variables are pre-processed and the call is sent to the Telegram Connector, which is already pure Java code. After sending the message, the transfer of the call is processed back to the Contact Center.

To simplify the settings, use the Configurable Variables, which allow you to display the settings of the internal variables of the application on the Experience Portal Web portal. This is necessary so that when changing the settings, do not recompile the application.

The block of variables looks like this:

image

As a configurable variable, the variable DNIS is used with sub-variables. To transfer variables to Java code, variables written in capital letters are used.

The preprocessing block looks like this:

image

Forgive me clean code lovers. The urla collection block looks awful. This features Orchestration Designer. Of course, it was more correct to compile it directly in the Java code in one line, but it was important for me to check which URL gets into the Java code and I had to compile it like this.

The connector itself looks extremely minimalistic:

  String response = ""; String str = mySession.getVariable(IProjectVariables.URL).getSimpleVariable().getStringValue(); str = str.replaceAll(" ", "%20"); IVariableField variable = mySession.getVariableField(IProjectVariables.RESPONSEINFO); variable.setValue(str); URL url; try { url = new URL(str); InputStream is = url.openConnection().getInputStream(); BufferedReader reader = new BufferedReader( new InputStreamReader( is ) ); String line = null; response = ""; while( ( line = reader.readLine() ) != null ) { response = response + line; } reader.close(); } catch (IOException e) { e.printStackTrace(); } 

The functions mySession.getVariable and mySession.getVariableField are needed to pass information from the application to the Java code and return the response back.

Those. we formed the URL according to the principle described above and launched it, transferring what the server returned back.

That's actually the whole application, but in general, and all the solution. The IVR web portal itself with Configurable Variables is as follows:

image

If someone is interested to look at a real demonstration of the prototype, then he can see it here .

Well, not without a cherry on the cake. More precisely, even two.

About the first I have already written. For the solution to work, you need to connect the application server to the Telegram via a proxy that is not in Russia. I hope this nonsense will ever end.

Well, the second cherry. Of course, the connection with the telegram must be encrypted and the connection goes through https. And, of course, a non-signed certificate is used for it. And this certificate Telegram does not give. And unlike the browser, the application server can not easily connect without a certificate. So the cherry on the cake is the process of finding this certificate and uploading it to the application server. After this procedure, all at once magically earned.

I believe that a person who will successfully complete my path will also successfully find this certificate. The main thing is that he knows that he must be found.

Thanks for attention.

Source: https://habr.com/ru/post/414811/


All Articles