How to create your own bot for Skype. What is not written in the documentation. Why do you need bots in Skype, how to use them

I have long wanted to try to write some simple bot to understand this process. Now I'm on vacation and I have enough free time to start writing for fun in this direction...

I decided to start with a simple bot that can only work with text. The bot will be based on the recently announced bot platform from Microsoft (Microsoft Bot Framework). I liked it because theoretically, one implemented bot can work for Skype and Telegram and the web and many other options. In order not to write a completely useless application, I will make an assistant bot for the developer that can perform actions such as:

  • Converting a string to uppercase
  • Converting a string to lowercase
  • Getting a new Guid
  • Converting a number from any number system to any
  • Converting Base64 strings to plain text
  • Plain text to Base64 string
  • Get date from string in UNIX format
  • Convert date to UNIX format
  • Generate a password of a given length

For such actions, I usually write snippets that are convenient to use if necessary. I use LINQPad to organize and run them. But sometimes I can do something not on my computer or even from a smartphone, in which case my bot can be useful. If you have any other ideas about what functionality can be added to this bot, write to me, I’ll be happy to implement them...

The bot will receive a string as input. We will separate the command and its parameters with spaces. The command itself will be either up to the first space, or the entire line if there are no spaces.

I will not describe the process of processing commands and how they are executed, since everything is extremely simple, and I will publish all the written code on GitHub.

Let's move on to something more interesting, namely, creating the bot itself. To work you need Visual Studio 2015, I recommend installing the available updates. Let's take advantage ready-made template to create bots “Bot Application template”, you can download it from this link aka.ms/bf-bc-vstemplate

The resulting zip archive must be copied to the directory " %USERPROFILE%\Documents\Visual Studio 2015\Templates\ProjectTemplates\Visual C#"After this, we can already create a new bot from this template.

Immediately after creation, the project has the following structure

We can run it and check what it can already do. For testing there is a separate application “Bot Framework Emulator”, you can find it from here http://download.botframework.com/botconnector/tools/emulator/publish.htm

Let's launch our application and emulator.

By default, the bot can return the length of the received message; this functionality is implemented in MessagesController:


Now I’ll add the previously described functionality to the bot. For this I will add new project“DeveloperToolsPack” which will be a Class Library and I will also add a project for Unit tests.

The DeveloperTools class is as follows:

Public class DeveloperTools ( private Dictionary _tools; public DeveloperTools() ( AddTool(new ToUpper()); AddTool(new ToLower()); AddTool(new NewGuid()); AddTool(new ConvertTo()); AddTool(new FromBase64()); AddTool(new ToBase64( )); AddTool(new FromUnixTime()); AddTool(new Password()); private void AddTool(ITool tool) ( if (_tools == null) ( _tools = new Dictionary (); ) if (!_tools.ContainsKey(tool.CommandName.ToLower())) ( _tools.Add(tool.CommandName.ToLower(), tool); ) ) public string Run(string str) ( if (!System.String. IsNullOrEmpty(str)) ( str = str.Trim(); var indexOfSpace = str.IndexOf(" ", StringComparison.Ordinal); string command; var commandText = ""; if (indexOfSpace != -1) ( command = str .Substring(0, indexOfSpace).ToLower(); commandText = str.Substring(indexOfSpace+1, str.Length - indexOfSpace-1); else ( command = str.ToLower(); ) if (_tools.ContainsKey(command )) ( return _tools.Run(commandText); ) else ( if (command == "help") ( var returnString = new StringBuilder(); foreach (var tool in _tools) ( returnString.Append(tool.Value.Description + "\n\r"); ) return returnString.ToString(); ) return $"Command \"**(command)**\" not found. See \"**help**\" command."; ) return "Please input a string"; ) )

In the bot itself, in the “MessagesController” we will replace the processing of the received message with

Var developerTools = new DeveloperToolsPack.DeveloperTools(); return message.CreateReplyMessage(developerTools.Run(message.Text));

You can run and test this bot.


If everything works as it should, you can go directly to publication. Let's create a regular web application in Azure; you can use the free tariff, since there is enough power for testing.

Now click on the project right click mouse and select Publish

Now you need to select "Microsoft Azure Web Apps"


And find the previously created application there. After this, you can click the “Publish” button and the application will be published.

Undoubtedly, bots are very promising direction. The Microsoft platform is very convenient and allows you to integrate with other services, which is undoubtedly a huge plus. The created bots, of course, are not limited to just text processing; they can perform much more complex functions. In this article, I showed how you can make a simple, but at the same time useful bot for Skype and publish it. The created bot, among other things, can work on many other platforms, such as Telegram, Facebook Messenger, GroupMe, Slack.

Happy programming.

P.S. The bot code was changed under new version Bot Framework

I won’t fuss, today I don’t consider Skype a convenient enough way to communicate with family, friends or colleagues. But I am forced to use it in cases where the addressee on the other side does not offer alternative options- at least the same whatsapp.

To diversify communication using Skype, use a set of features that everyone needs to know.

1. Add phonebook contacts to your friends list

To add phone book contacts to your friends list, go to the settings menu in the profile section and move the corresponding switch to the active position.

Now you will see in the list of Skype contacts all the phone book entries that use the service.

And this feature appeared only in the latest updates. mobile application for iOS.

2. Send location to save time

My friends and I actively use this feature via WhatsApp when we are trying to find each other in our hometown or on a trip. And it is also on Skype.

Just click on the corresponding button above the keyboard, adjust the location and confirm your choice. Profit.

3. Mark your favorite interlocutors from the general list

In the contacts menu, click on add to favorites and mark the recipients with whom you communicate or plan to communicate most often.

This way, you will save time searching for them in the future - your favorite entries are always displayed at the top of your Skype phone book.

4. View the time of swipe messages

Swipe from right to left in the conversation menu with someone and see the time each message was sent in the conversation.

5. Use hidden emoticons from the list of the best below

To send hidden smiley, you need to write it in text according to the tables below.

On the left is the image, in the center is the name, on the right is the code ( parentheses are also part of the code).

Please.

6. Transfer Skype contacts to your interlocutors in a couple of taps

For this purpose, the service’s mobile application has a special button that is available during correspondence.

Using this feature, you can recommend contacts from your phone book to friends to resolve issues or connect close relatives together.

7. Set Skype statuses according to your personal needs

Use service statuses wisely:

  • Online- the user is ready to communicate
  • Offline- Skype is turned off or there is no network
  • Out of office- ready to read messages when he returns
  • Do not disturb- the user is busy and will not receive a notification about your message
  • Invisible- for everyone this status will look like offline

This will make life easier.

8. Try chatting with bots to evaluate them personally

The current list of Skype bots is available on the service’s official website - here is the link. To start communicating with a robot, you just need to add it to your friends list.

Developers already offer virtual assistants, vacation guides, medical consultants, and so on.

It's a pity, most bots only communicate in English. But you can still find something interesting just for yourself.

9. Create group video calls with friends

In one of latest updates Skype has added the ability to make group video calls with up to 25 users in one such chat.

To activate the feature, just create a group chat and click on the usual button to make a video call.

10. Record video messages to share with contacts

About launching bots in Skype - it's time to learn how it works. Below the cut is a short description possible problems. For those who can't wait to see the result, here it is - MetricsBot.

Bot Framework vs. Skype Bot API

First, you should understand that there is a Bot Framework, which allows you to create bots for many instant messengers, incl. and for Skype, and there is Skype Bot API, which allows you to create bots specifically for Skype. Each has its own documentation, its own bot directory (?) and its own bot registration. It seems obvious that these are different things, but I spent quite a lot of time trying to understand the Bot Framework documentation and registering a bot in it, when I expected that I was creating a bot without a framework. Next we will talk about the Skype Bot API, Bot Framework we don’t need it, we don’t need to register anything there either. There is a Skype SDK for Node.js and I didn’t use them either, because I wrote the bot in Python.

Useful links

First, a small set of useful links (all links are in English):
  • Your applications (here you need to create a new application and get the app id and client secret)
  • Managing your bots (here you need to create a new bot, indicating the app id received earlier)
In principle, from the documentation it is clear how the bot works and how it interacts with Skype, so I won’t describe this part - I’ll tell you about the difficulties.

Authorization

This turned out to be the most time consuming part for me. The documentation says that to authorize you need to obtain a token and then use it in the HTTP header on each request:

Authorization: Bearer oauth2-token

However, for some reason, the documentation forgot to indicate which scope should be used to obtain a token. The correct answer (can be found in the Node.js SDK code) is https://graph.microsoft.com/.default.
But here the most interesting thing begins - if you create a URL for confirmation by the user (= the owner of the bot), then receive auth_code, and then try to exchange this code for access token, then the problem will arise at the very first step - when opening the created URL, Microsoft complains about the wrong scope. The correct scope, by the way, is not in the list 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 was able to get a token, but I couldn’t interact with Skype with it.
The solution turned out to be unexpected - to receive an 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= &client_secret= &grant_type=client_credentials&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default" "https://login.microsoftonline.com/common/oauth2/v2.0/token"

Returns in response access_token And expires_in(without any refresh_token). I've never seen OAuth like this before.

Sending messages

Sending messages is quite 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. They forgot to indicate in the documentation that requests should be sent via http s.
You can use html tags in the text. Exactly which ones are still unknown (there is no list in the documentation).
There are interesting and undescribed restrictions on the text you send. For example, you cannot use the symbols in the text & , < And > . Inability to transmit a symbol & creates a problem when passing links. Another problem when transferring links is automatically generated previews for each link. In my bot MetricsBot there are three links in the invitation text, Skype creates three previews. There is no way to disable this yet.

Publishing a bot

After creating the bot, you can try to publish it (before this, the number of users of the bot is limited - only 100 people can use it). How long the publication process takes is not clear; this is not in the documentation. My bot has not yet been published. On the official forum, my question on this topic is ignored (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.

Otherwise, creating a bot for Skype is quite simple.

Following some other instant messengers and social services, Skype also decided to “legalize” bots. And at the end of March 2016, the developers announced this function in their application. What is it intended for? Skype bot, why, in fact, can it be useful to the most ordinary user and how can you add some kind of bot to yourself?

Bots in virtual space

In fact, bots are not an invention of modern virtual space. The bot is computer program, which is designed to “pretend” in every possible way an ordinary person on the web. And the first bots, oddly enough, arose... in computer games. It was with the development of online shooters - such as DOOM, Quake and the like - that users began to write so-called bots - software robots that could keep company in online battles. After all, not all players then had access to computer network, but I still wanted to play...

Today, bots are both pleasant and unpleasant additions to almost any social network or messenger.

At first they only irritated me with their stupidity. Over time, however, programmers realized that bots could also be used to provide useful service to humanity. And now large number bots are written to order and on a paid basis. For example, to answer customer questions, issue information about keywords in messenger...

Assigning bots in Skype

The Skype software robot can somehow imitate the online behavior of a living person. Since its announcement, a variety of Skype bots have appeared. Some simply entertain the user by playing various games with him, others may search useful information on the Internet, others can chat...

In short, the choice is really great. However, most of the bots still function in English, some are available only in the United States. However, there are fewer and fewer restrictions.

To make sure your bot is safe, you need to look at its profile before adding it. This should contain the phrase “Skype Certified”. In addition, the bot's avatar always has a hexagonal shape, whereas for all other users it is round. In addition, next to the avatar of the approved bot there is a “tick” on a gray background.

How can you add this or that bot? It's quite simple. To do this:

  1. You need to download Skype on your device;
  2. Further actions depend on what operating system Skype works. For example, on Android there is a special menu item "Contacts". That's what it's called - "Bots". In iOS there is a Bots icon in the tab "Recent". The desktop version of Skype Windows has a special icon in the side toolbar. In the browser version of Skype you need to select "Bot Review";
  3. Next, all you have to do is click on "Add bot" or "Begin".

A list of certified and approved bots can be found on the project page: https://support.skype.com/ru/faq/FA34655/dostupnye-boty-skype.

If the bot is boring or suspicious, you can block or delete it. This is done in exactly the same way as with the most common contacts on Skype.

It remains to add that bots are available only in the latest release versions of Skype. So it makes sense to update the program from official sources.

Knowing what Skype bots are, you can significantly expand your ability to use this multilateral program for communication and calls.



CATEGORIES

POPULAR ARTICLES

2024 “mobi-up.ru” - Garden plants. Interesting things about flowers. Perennial flowers and shrubs