In previous chapters, we learned to develop a chatbot from the Azure Portal, connecting it with question-and-answer services, LUIS, and others; developed message templates to engage users; explored different business scenarios in which we can deploy chatbots; and created a better user experience using chatbots. In this chapter, we focus on integrating Azure chatbots with different channels. Again, the approach is simple and clear for both technical and nontechnical readers to understand. The objective of showing the integration of a chatbot with other applications is to demonstrate the convenience behind Azure chatbots in which a high level of coding is not mandatory. By using the standard services available in Azure Portal, integration is easy to achieve.
To start, let’s look at integrating Azure with different communication apps. At the end of the chapter, I compare different cloud platforms and show that the Azure platform is the best for chatbot development.
Integration of a Chatbot with Communication Apps
- 1.
Sign in to Azure Portal.
- 2.
Choose the chatbot to be configured
- 3.
Under Bot Management, click Channels and choose the channel you wish to use.
After you post the channel configuration, users can start using the chatbot on that channel.
Let’s now look at connecting chatbots with other channels.
Connect a Chatbot to Cortana
- 1.Open Azure Portal, then click the Cortana icon in the Channels section.
- 2.When connecting a chatbot to Cortana, information is required to be updated; this is done in the registration window. Registration consists of the following:
Skill icon: The icon is displayed in the Cortana canvas when Cortana Skill is involved.
Display name: The display name is the name of the Cortana Skill chatbot to be displayed in the user interface. It accepts no more than 30 characters.
Invocation name: The invocation name is the name used by users to invoke or call the Cortana Skill chatbot with voice or text. Invocation is part of the essential natural language and is a call, request, or petition to a chatbot to perform an action based on an utterance. An utterance containing more than three words is difficult to recognize or distinguish. “One-way ticket” is easy compared to “two-way train ticket.” While invoking, avoid using duplicate names for your chatbot, terms such as bot or chatbot, homophones such as wait or weight, hard-to-pronounce words, and names that combine multiple words into one, such as five-star hotel.
Users invoke skills by saying the invocation phrases:
Example Invocation Phrases with Connecting WordsAsk <Invocation Name> to <Utterance>.
Search <Invocation Name> for <Utterance>.
Get <Invocation Name> to <Utterance>.
Example Invocation Phrases without User Utterances
Tell <Invocation Name>
Start <Invocation Name>
Run <Invocation Name>
Example Invocation Phrases without Connecting Words
Ask <Invocation Name> <Utterance>
Use <Invocation Name> <Utterance>
Search <Invocation Name> <Utterance>
- 3.
As seen in Figure 5-4, to manage user identity, slide the option to enable it.
Select “Sign-in at invocation” when you expect Cortana to sign in users when they invoke Skill.
Select “Sign-in when required” when you do not expect users to sign in with Skill when invoked; rather, they sign in using features such as card attachments.
Enter the account name, which is the name of the Skill chatbot you would like to be displayed after sign-in.
Enter the client ID for third-party services. This is your chatbot’s application ID and you get it when you’ve registered your bot.
Enter the space-separated list of scopes. The Scope parameter is a space-separated list of OAuth scopes that indicates which parts of the user’s account your app can access. Examples include files, chats, reactions, and searches, followed by classes of actions such as read, write, and history (includes access to direct messages).
Enter the authorization URL. Set it to https://login.microsoftonline.com/common/oauth2/v2.0/authorize .
Under “Token options,” select POST to post the token in the token URL field or select GET to get the token.
- Enter the grant type. To use the code grant flow, use Authorization code or, to use implicit grant flow, select implicit. OAuth gives users limited access to applications. Code grant flow and implicit grant flow are OAuth2.0 specifications for client applications to get an access token that represents user permission for the client application to access their data. These standards are used from a security standpoint.
Authorization code grant : The user logs in from the client app and the authorization server returns an authorization code to the app. The app then exchanges the authorization code for the access token. It is possible to obtain a prolonged access token; it can be renewed with a refresh token.
Implicit code grant : The user logs in from the client app and the authorization server issues an access token to the client app directly. This grant type does not allow the issuance of a refresh token.
Here is what to fill in. Refer Figure 5-6 for details:Set token URL to https://login.microsoftonline.com/common/oauth2/v2.0/token .
Select HTTP Basic under “Client authorization scheme”.
Do not check the option for Internet access required to authenticate users.
Select “Request user profile data” (optional), if you want the Skill chatbot to access information such as name, location, workplace, and more. This generates customized messages such as “<Name>, how was your day at <workplace>?”
- Finally, select Deploy Cortana. This brings you to the Channel blade or menu screen. From there, you should see Cortana connected to your chatbot.
Connect a Chatbot to Skype
Skype has been adopted by many organizations for their employees to enable instant messaging and audio and video calls, and to share content. By connecting a chatbot with Skype, users can actually interact with the chatbot in Skype through the Skype interface. To do this, follow these steps:
Web control: Click “Get embed code” to get the embedded code. This code is hosted on your web site or mobile app, at which point the user can interact with the chatbot with Skype in the background. After you click this button, you are redirected back to the Configure screen (Figure 5-8).
Messaging: In Messaging, you configure the manner in which your chatbot sends and receives messages in Skype.
Calling: In Calling, you configure the calling feature of Skype in the chatbot. You can enable it or keep it disabled. If you enable it, use interactive voice response functionality or real-time media functionality.
Groups: In Groups, you configure how to add chatbots to a group for instant group messaging and group calls.
Publish: In Publish, you publish your chatbot enabled with Skype.
Connect a Chatbot to Telegram Messenger
- 1.To create a new Telegram chatbot, visit BotFather: https://telegram.me/botfather (Figure 5-9).
- 2.
- 3.Assign a friendly name to your Telegram chatbot. As you can see in Figure 5-11, we will call our bot Delightful Bot.
- 4.Specify the username. As you can see in Figure 5-12, our username is DelightfulBot .
- 5.Copy the access token of the Telegram chatbot (Figure 5-13).
- 6.
Last, open Azure Portal, click the Channel blade, click the Telegram icon and paste the access token. Then, click Submit and check Enabled. Our chatbot is now ready to communicate with Telegram users.
Connect a Chatbot to Kik
- 1.Install the Kik messaging app and sign in using a user ID and password (Figure 5-14).
- 2.After installing the app, log in to the Kik portal using a mobile phone. Then, open the Kik developer’s portal (Figure 5-15).
- 3.Follow the chatbot setup process and give a name to it (Figure 5-16).
- 4.Copy the name and API key from the Configuration tab. Click Save (Figure 5-17).
- 5.Open Azure Portal, click the Channel blade, and click the Kik icon. Paste the Kik credentials and enable the chatbot by clicking Submit Kik Credentials.
Connect a Chatbot to a Direct Line
- 1.Open Azure Portal. In the Channel blade, select the direct-line icon (Figure 5-19).
- 2.To configure a direct line, create a site that represents your client application, which will be connected to your chatbot. To do this, click “Add new site” (Figure 5-20) and name it.
- 3.After creating the site, the Microsoft Bot Framework generates secret keys to be used by the client application to authenticate the direct-line API request, which is issued by the application to interact with your chatbot. Click Show for the corresponding key to view a key in plain text (Figure 5-21) .
- 4.Copy and store the key that is shown (Figure 5-22) and use it to authenticate direct-line API requests that your client issues to communicate with your chatbot.
- 5.
Last, open Azure Portal, click the Channel blade, and click the direct-line icon. Use the direct-line reference the client application will use to communicate with your chatbot. You can repeat this process, beginning with “Add new site,” for each client application that you want to connect to your Chatbot.
Connecting a Chatbot to Office 365 E-mail
- 1.
Open the e-mail channel in Azure Portal, click the Channel blade for the e-mail.
- 2.Enter Office 365 credentials in the e-mail channel configuration (Figure 5-24).3
- 3.
The e-mail channels support custom sending properties to create customized replies. You can delineate HTML as the body of the message, indicate a subject for the e-mail subject line, assign importance to highlight e-mail priority, and add recipients in the TO, CC, and BCC fields using a semicolon as a separator.
Connecting a Chatbot to Facebook
- 1.Create a new Facebook page or use an existing page. Go to the About Us page and copy and save the page ID. Then, create a Facebook app on the page and generate an app ID and an app secret ID for it. Insert the display name and contact e-mail for communication (Figure 5-25), then click Create App ID.
- 2.Copy the generated app ID and app secret ID, and save them to the basic settings section (Figure 5-26).
- 3.Select the Advanced option and move the Allow API Access to App Settings slider to Yes (Figure 5-27).
- 4.Then, enable Facebook Messenger in the new Facebook app by clicking Set Up in the Messenger blade (Figure 5-28).
- 5.
- 6.To enable Webhooks to forward messaging events from Facebook Messenger to your chatbot, click Setup Webhooks (Figure 5-30).
- 7.Now go to Azure Portal and, under Channels, click the Facebook Messenger icon. From there, copy the callback URL and verification token for the Facebook URL to the Webhook setup (Figure 5-31).
- 8.Now go to the Webhooks setup page and select the page you created for the Webhook to subscribe to the Facebook page (Figure 5-33).
- 9.
Log in to Azure Portal, choose Channel, and click the Facebook Messenger icon. Then, enter the Facebook app ID, the Facebook app secret ID, the page ID, and the page access token values copied earlier from Facebook Messenger. Multiple Facebook pages can use the same chatbot by adding additional page IDs and access tokens.
To publish to the chatbot, it has go through the Facebook review and approval process. In general, Facebook requires a privacy policy URL and Terms of Service URL on its basic app settings page. To create a privacy policy, go to third-party resource links in the Code of Conduct page. The Terms of Use page contains sample terms to create a relevant Terms of Service document. For the review process to start, publish changes made to Facebook Messenger. The chatbot will be tested to ensure it is compliant with Facebook policies. When approved, in the App dashboard under App Review, set the app to Public. Ensure the Facebook page associated with this chatbot is published. Status appears in the Pages setting.
Connect a Chatbot to Facebook Workplace
- 1.Click the Admin Panel tab of Facebook at Workplace. Click Integrations and then click Create Custom Integration (Figure 5-35).
- 2.Enter a display name and profile picture for this app. Set Allow API Access to App Settings to Yes and then copy and store the app ID, app secret ID, and app token displayed onscreen (Figure 5-36).
- 3.You now have a custom integration. You can find this page of type “Bot” in your workplace community, as shown in Figure 5-37 .
- 4.
As before, log in to Azure Portal, paste the Facebook app ID, Facebook app secret ID, and page access token values (Figure 5-36). Use the numbers following the integration name on its About page, which is similar to the situation when we used the page ID from the About Us Facebook page.
- 5.
Webhooks can be connected with the credentials shown in Azure in the case of Facebook Workplace. Submit for review and, when approved, Facebook Workplace is available for users. Publish the custom integration app and make it public, as we did earlier for Facebook.
Connect a Chatbot to GroupMe
- 1.Create an account in GroupMe. Complete the GroupMe application and use https://groupme.botframework.com/Home/Login as the callback URL (Figure 5-38).
- 2.Copy your client ID in Redirect URL and your access token as shown in Figure 5-39 .
- 3.In dev.botframework.com, paste the access token into the Access Token field and the client ID into the Client ID field (Figure 5-40). Click Save to enable the chatbot.
Summary
With this, we have come to the end of this chapter. We saw how easy it is to connect an Azure chatbot to Cortana, Skype, Telegram Messenger, the Kik messaging app, a direct line, Office 365 e-mail, Facebook Messenger, Facebook Workplace, and GroupMe. In the next chapter, we examine the benefits of using Azure chatbots.