📜 ⬆️ ⬇️

How to create your bot for Skype. What is not written in the documentation



Some time ago I was talking about my Telegram bot , which can show data from Google Analytics. And then Microsoft announced the launch of bots in Skype - it's time to learn how it works. Under the cut - a small description of possible problems. Who can not wait to see the result, here it is - MetricsBot Add Bot to Skype .

Bot Framework vs. Skype Bot API


First of all, it is worth understanding that there is a Bot Framework , which allows you to create bots for many instant messengers, incl. and for Skype, and there is a Skype Bot API that allows you to create bots specifically for Skype. Each has its own documentation, its own catalog of bots (?) And its own registration of bots. It seems obvious that these are different things, but I spent quite a lot of time trying to understand the Bot Framework documentation and register the bot in it when I expected to create a bot without the framework. Then we will talk about the Skype Bot API, we don’t need the Bot Framework, there’s nothing to register there either. There is a Skype SDK for Node.js and for C # . I did not use them either, because wrote a bot in Python.

useful links


First, a small set of useful links (all links are in English):

In principle, it is clear from the documentation how the bot works and how it interacts with Skype, therefore I will not describe this part - I’ll tell you about the difficulties.
')

Authorization


It turned out to be the most time consuming part for me. The documentation states that for authorization you need to get a token, and then use it in the HTTP header with each call:

Authorization: Bearer oauth2-token

However, in the documentation for some reason forgot to specify which scope should be used to obtain the token. The correct answer (can be found in the Node.js SDK code) is https://graph.microsoft.com/.default .
But the most interesting thing begins - if you create a URL for confirmation by the user (= bot owner), then get auth_code , and then try to exchange this code for access token , the problem will arise at the very first step - when opening the created URL, Microsoft swears at the wrong scope . The correct scope, by the way, is not in the list of possible options in the Microsoft documentation . I tried to specify a different scope - openid offline_access https://graph.microsoft.com/user.read , in this case I managed to get a token, but I couldn’t interact with it with Skype.
The solution was unexpected - to get access_token, it was necessary to send a regular POST request:

curl -X POST -H "Cache-Control: no-cache" -H "Content-Type: application/x-www-form-urlencoded" -d 'client_id=<your-app-id>&client_secret=<your-app-secret>&grant_type=client_credentials&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default' 'https://login.microsoftonline.com/common/oauth2/v2.0/token'

Access_token and expires_in are returned in response (without any refresh_token ). I did not meet such OAuth yet.

Sending messages


Sending messages is pretty simple -

POST /v2/conversations/8:alice/activities HTTP/1.1
Host: apis.skype.com
Authorization: Bearer oauth2-token
{
"message": {"content" : "Hi! (wave)"}
}


Requests are sent to apis.skype.com. The documentation forgot to specify that requests should go on http s .
In the text, you can use html-tags. What exactly is not yet known (there is no list in the documentation).
There are interesting and undescribed restrictions on the text sent. For example, in the text you cannot use the symbols & , < and > . The inability to transmit the & symbol creates a problem when passing links. Another problem with the transfer of links - automatically generated previews for each link. In my bot MetricsBot in the invitation text are three links, Skype creates three previews. Disable it while it is impossible.

Bot Publish


After creating a bot, you can try to publish it (until then, the number of bot users is limited - only 100 people can use it). How long the publishing process takes is not clear; this is not documented. My bot has not yet been published. On the official forum, my question on this topic is bypassed (although Microsoft employees answer my other questions).
Please note that to publish a bot, you must disable the use of the bot in group chats.

The rest - the creation of a bot for Skype is quite simple.

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


All Articles