Create chatbot for any messenger in API.chat

There are a lot of messengers in the world. Connect each one of them and maintain every connection is a very complex job. Luckily a Microsoft already did most of the job for us and provide us with Azure Bot Channel Registration - a web service to connect your chatbot to major messenger platforms. It's free for almost every channel except web-chat and for web-chat, it's free for 10000 messages per month.

API.chat engine is fully compatible with Bot Framework, so you can use Bot Channel Registration to connect 15+ messengers to your API.chat chatbot. Here how you can do it.

Create API.chat chatbot

First, you need to create an API.chat chatbot. Here you can check how to do it.

Create an Azure Bot Channel Registration application

Next, you need to create Azure Bot Channel Registration and obtain pair of MicrosoftAppId and MicrosoftAppPassword to use it later.

1. In your browser, navigate to the Azure portal. If you do not have a subscription, you can register for a free account.

2. In the left panel, click Create a resource.

3. In the top center search bar, enter bot. From the drop-down list select Bot Channels Registration.

Создание регистрации Bot
Select Bot Channels Registration

4. Click the Create button.

5. In the Bot Channels Registration form, provide the requested information about your bot as specified in the table below.

Setting Suggested value Description
Bot name <Your bot's handle> The bot handle is a unique identifier for your bot. You can choose a different display name for your bot in the Settings blade after the bot has been created.
Subscription <Your subscription> Select the Azure subscription you want to use.
Resource Group <Your resource group name> Create a new resource group or select an existing one.
Location West US Choose the geographic location for your resource group. It's usually best to choose a location close to you. The location cannot be changed once the resource group is created.
Pricing tier F0 Select a pricing tier. You may update the pricing tier at any time. For more information, see Bot Service pricing.
Messaging endpoint https://<your bot name>.azurewebsites.net/api/messages Enter the URL for your bot's messaging endpoint. You should leave this field empty since you will enter the required URL after deploying the bot.
Application Insights On Decide if you want to turn Application Insights On or Off. If you select On, you must also specify a regional location.
App ID and password Create App ID and password Use this option if you need to manually enter a Microsoft App ID and password.

6. Leave the Messaging endpoint box empty for now. You'll enter the required URL after deploying the bot.

7. Click Microsoft App ID and password, highlighted in the screenshot below. The next steps allow you to create the registration application password and application ID to be used in your bot configuration files appsettings.json (.NET), .env (Javascript) and config.py (Python).

Параметры регистрации программы-робота

8. Click Create New.

9. Click the Create App ID in the App Registration Portal link.

10. In the displayed App registration window, click the New registration tab in the upper left.

11. Enter the name of the bot application you are registering.

13. Click the Register button. Once completed, Azure displays the overview page for the application.

14. Copy the Application (client) ID value and save it in a file.

15. In the left panel, click Certificate and secrets.

16. Under Client secrets, click New client secret.

17. Add a description to identify this secret from others you might need to create for this app.

18. Set Expires to your choosing.

19. Click Add.

20. Copy the client secret and save it to a file. Make sure to keep the file in a secure place.

21. Go back to the Bot Channel Registration window and copy the App ID and the Client secret in the Microsoft App ID and Password boxes, respectively.

22. Click OK.

23. Click the Create button and wait for the resource to be created. It will show in your resources list.

Create (connect) API.chat Universal Channel

Use Universal channel POST endpoint to create universal channel and connect your chatbot to the Bot Channel.

-- CODE lang-bash -- curl -v -X POST "https://bot.api.chat/channels/universal/botName" -H "Cache-Control: no-cache" -H "Ocp-Apim-Subscription-Key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" --data-raw '{ "AppId": "appId", "Password": "appSecret" }'

As a result you will get a JSON with webhook url to set as Messaging endpoint

-- CODE lang-json -- { "Connector": { "AppId": "appId", "Password": "appPassword" "MessagingEndpoint": "https://bot.api.chat/endpoint/universal/appId?subscription-key=XXXXXXXXXXXXX" } }

Set this webhook on Configuration under Bot Management of your Bot Registration

Connect a Bot Channel to channels

Now you can connect actual messengers to your bot channel

  1. Sign in to the Azure Portal.
  2. Select the bot that you want to configure.
  3. In the Bot Service blade, click Channels under Bot Management.
  4. Click the icon of the channel you want to add to your bot.
Connect to channels

After you've configured the channel, users on that channel can start using your bot.

Don't miss these stories: