In this article I want to describe a simple example of how a multi-protocol bot works through the
Microsoft Bot Connector API - v3.0 . On
skype- like bots, there are already articles on Habré:
“How to create your own bot for Skype. What is not written in the documentation " by
and7ey and
" Hello, Bot! Chat bots are the next generation of apps? ” By
shwars . But in the first there is a speech about the work through apis.skype and the variant described there is not multiprotocol, and in the second the implementation is described via C #, but I do not know how to do it.
Who needs this article and why?
Firstly, the “guy” who wants to make his bot, but does not know how to do C #, but who knows how to use REST.
Secondly, to me, since I spent a fair amount of time analyzing several versions of the API and understanding which API and how I should use it. Therefore, I would like to consolidate my experience
on paper in the article (ok, I will no longer use the chip with a strikethrough text).
Authorization
Fully (as far as I was able to evaluate) is considered in the article I mentioned above - in
this one . We do as described, we get a token and a start - we are “on the first base” (this is not a generally accepted analogy about the bases, where on the third we will be given a boob tits, no, this is not it).
')
Receive messages
The bot should have an endpoint where requests with a json-body will come. For example, a message sent to the bot via skype with the text “hello, bot” will come like this:
json {
"type": "message",
"id": "1q80QckzCi3wL6zg",
"timestamp": "2016-08-16T12: 56: 16.49Z",
"serviceUrl": "https://skype.botframework.com",
"channelId": "skype",
"from": {
"id": "29: 1Phe2HAxz6CD9uc1O_PVl_Zih6doxIe_KuyrQ9eANUbs",
"name": "avvero"
},
"conversation": {
"id": "29: 1Phe2HAxz6CD9uc1O_PVl_Zih6doxIe_KuyrQ9eANUbs"
},
"recipient": {
"id": "28: 300cbb48-78e0-4998-8e85-4f4c7ccb5aee",
"name": "notify_bot"
},
"text": "hello, bot",
"entities": [
]
}
What is especially important to us in this request:
- conversation.id - conversation ID
- channelId - channel identifier
These two parameters are especially important because on the basis of them the url is determined for sending requests to botframework. At the same time, the role of conversationId is mentioned in the API
description (
swagger ), but with channelId, not everything is so obvious, more precisely, nifiga (technical term) is not obvious. For example, messages from the bot for the skype channel should go here:
https: //
skype .botframework.com / v3 / conversations / {conversationId} / activities,
And for the telegram here:
https: //
telegram .botframework.com / v3 / conversations / {conversationId} / activities.
I did not see this in the documentation and this is bad, since most of the time was spent on identifying this feature.
Sending messages
For skype, the minimum request body will be:
json {
"type": "message",
"text": "hello"
}
And for a telegram like this (you need a
from object):
json {
"type": "message",
"from": {
"id": "avvero_notify_bot",
"name": "avvero"
},
"text": "hello"
}
Cards
Not texts uniform. You can send cards as well (here is an example of a message for a telegram, for skype it is possible without from):
json {
"type": "message",
"from": {
"id": "avvero_notify_bot",
"name": "avvero"
},
"text": "hello",
"attachments": [
{
"contentType": "application / vnd.microsoft.card.hero",
"content": {
"title": "title",
"subtitle": "subtitle",
"text": "text",
"images": [
{
"url": "https://pp.vk.me/c7011/v7011856/3160d/HVELORSo5KM.jpg",
"alt": "hello thumb"
}
],
"buttons": [
{
"type": "imBack",
"title": "Yes",
"value": "yes <context offer = \" ... \ "/>"
},
{
"type": "imBack",
"title": "No",
"value": "no"
},
{
"type": "openUrl",
"title": "Google",
"value": "https://disney.radisson.com"
}
]
}
}
]
}
In skype it looks like this:

In a telegram like this:

the end
Well, that's basically all I wanted to tell. It is worth mentioning the problems when using such a bot.
For skype:
For telegram:
- It is not possible to contact the bot in the group through the @ sign, the bot message does not go, the bot message goes if you put the / sign in front of the message, i.e. so "/ hi bot"
Thanks for attention!