© Charles Waghmare 2019
C. WaghmareIntroducing Azure Bot Servicehttps://doi.org/10.1007/978-1-4842-4888-1_5

5. Chatbot Integration

Charles Waghmare1 
(1)
Mumbai, India
 

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

As seen in Figure 5-1, channels such as Facebook Messenger, Kik, WhatsApp, and others can be connected to chatbot. The Microsoft Bot Service, available in Azure Portal, helps to connect chatbots with various channels. The Microsoft Bot Service also helps to facilitate interaction between chatbots and users. In addition to standard channels such as Facebook Messenger (Figure 5-1), this service also helps connect to nonstandard channels, such as your client’s application. For channels, you must provide channel information to run chatbots on that channel. Most channels require your chatbot to have its account on the channel; other channels such as Facebook Messenger demand that your chatbot be registered with the channel as well.
../images/478917_1_En_5_Chapter/478917_1_En_5_Fig1_HTML.jpg
Figure 5-1

Connection between a chatbot and a communication app

The Microsoft Bot Framework normalizes messages from the chatbot to the channels. Normalizing procedures involves converting messages from the channel schema to the chatbot schema and vice versa. Let’s say you have a situation in which an e-mail greeting is sent from the chatbot schema to the channel schema that cannot be displayed as is because of missing functionalities in the chatbot. In this case, a greeting card is displayed and a link for user action is shown in the channels. Any Azure chatbot you have created (see Chapter 1) can be connected to channels by means of a simple configuration done inside the channels. The configuration to connect the chatbot and the channels is done using the following steps and is shown in Figure 5-2 .
  1. 1.

    Sign in to Azure Portal.

     
  2. 2.

    Choose the chatbot to be configured

     
  3. 3.

    Under Bot Management, click Channels and choose the channel you wish to use.

     
../images/478917_1_En_5_Chapter/478917_1_En_5_Fig2_HTML.jpg
Figure 5-2

Connecting a chatbot to a channel

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

Cortana is a speech-enabled channel that has the capability to receive and send voice messages along with text. For any chatbot to be connected with Cortana, it should be designed to accept and receive speech instructions. Cortana Skill is the name of the chatbot that involves a Cortana client; publishing any chatbot that connects to Cortana adds the chatbot to Cortana Skill. To integrate with Cortana, as seen in Figure 5-3, follow these steps:
  1. 1.
    Open Azure Portal, then click the Cortana icon in the Channels section.
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig3_HTML.jpg
    Figure 5-3

    Connecting a chatbot to Cortana

     
  2. 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 Words
      • Ask <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. 3.

    As seen in Figure 5-4, to manage user identity, slide the option to enable it.

     
../images/478917_1_En_5_Chapter/478917_1_En_5_Fig4_HTML.jpg
Figure 5-4

Managing user identity

As seen in Figure 5-4, upon enabling the option, mandatory and nonmandatory fields need to be updated. In addition, a chatbot must be published in Azure before connecting it to Cortana. To enable user identity, you need to set up the identity (Figure 5-5).
../images/478917_1_En_5_Chapter/478917_1_En_5_Fig5_HTML.jpg
Figure 5-5

Managing general chatbot information

  • 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.
      ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig6_HTML.jpg
      Figure 5-6.

      General Chatbot Information

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:

  1. 1.
    Open Azure Portal, click the Channel blade, and click the Skype icon (Figure 5-7).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig7_HTML.jpg
    Figure 5-7

    Connecting chatbot and Skype

     
  2. 2.
    After you choose Skype, you need to configure settings for Web control, Messaging, Calling, Groups, and Publish (Figure 5-8) .
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig8_HTML.jpg
    Figure 5-8

    Configuring settings for Skype

     
  • 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

Let’s configure a chatbot to communicate with people as Skype using the Telegram Messenger app:
  1. 1.
    To create a new Telegram chatbot, visit BotFather: https://telegram.me/botfather (Figure 5-9).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig9_HTML.jpg
    Figure 5-9

    Visiting BotFather

     
  2. 2.
    Create a new chatbot using the command /newbot to create a new bot (Figure 5-10).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig10_HTML.jpg
    Figure 5-10

    Choose the /newbot command to create a new chatbot

     
  3. 3.
    Assign a friendly name to your Telegram chatbot. As you can see in Figure 5-11, we will call our bot Delightful Bot.
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig11_HTML.jpg
    Figure 5-11

    Give your bot a friendly name

     
  4. 4.
    Specify the username. As you can see in Figure 5-12, our username is DelightfulBot .
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig12_HTML.jpg
    Figure 5-12

    Specify the username

     
  5. 5.
    Copy the access token of the Telegram chatbot (Figure 5-13).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig13_HTML.jpg
    Figure 5-13

    Copy the Telegram chatbot token

     
  6. 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

Now we’ll configure a chatbot to connect to the Kik messaging app to engage users. Follow these steps:
  1. 1.
    Install the Kik messaging app and sign in using a user ID and password (Figure 5-14).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig14_HTML.jpg
    Figure 5-14

    Install the Kik messaging app

     
  2. 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).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig15_HTML.jpg
    Figure 5-15

    Log in to the Kik developer’s portal

     
  3. 3.
    Follow the chatbot setup process and give a name to it (Figure 5-16).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig16_HTML.jpg
    Figure 5-16

    The chatbot setup process

     
  4. 4.
    Copy the name and API key from the Configuration tab. Click Save (Figure 5-17).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig17_HTML.jpg
    Figure 5-17

    Configuration setup

     
  5. 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.
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig18_HTML.jpg
    Figure 5-18

    Submit credentials

     

Connect a Chatbot to a Direct Line

To connect a chatbot to a direct line, do the following:
  1. 1.
    Open Azure Portal. In the Channel blade, select the direct-line icon (Figure 5-19).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig19_HTML.jpg
    Figure 5-19

    Choose the direct-line icon from the Channel blade

     
  2. 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.
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig20_HTML.jpg
    Figure 5-20

    Create a new site

     
  3. 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) .
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig21_HTML.jpg
    Figure 5-21

    Secret keys

     
  4. 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.
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig22_HTML.jpg
    Figure 5-22

    Secret key to authenticate direct-line API requests

     
  5. 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.

     
As seen in Figure 5-19, which shows the Get Embed Code option, you can use embedded code for configuration purposes. If you refer back to Figure 5-20, you can set the size of <iframe> with'width'and 'height' tags or add a class to position and size the frame with cascading style sheets. Secret keys can be used, as seen in Figure 5-23.
../images/478917_1_En_5_Chapter/478917_1_En_5_Fig23_HTML.jpg
Figure 5-23

Configuration using embedded code

Connecting a Chatbot to Office 365 E-mail

Chatbots can be connected with Office 365 e-mail, similar to other communication channels. If you configure your chatbot to connect to e-mail, then the chatbot has multiple capabilities, such as sending notifications when new mail arrives in a mailbox, setting up predefined decline responses to meetings if there is conflict, and so on. To connect your chatbot to Office 365 e-mail, follow these steps:
  1. 1.

    Open the e-mail channel in Azure Portal, click the Channel blade for the e-mail.

     
  2. 2.
    Enter Office 365 credentials in the e-mail channel configuration (Figure 5-24).3
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig24_HTML.jpg
    Figure 5-24

    Connect your bot to your Office 365 e-mail account

     
  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

To configure a chatbot to communicate with Facebook Messenger, enable Messenger on a Facebook page and connect it with the chatbot:
  1. 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.
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig25_HTML.jpg
    Figure 5-25

    Generate an app ID and an app secret ID

     
  2. 2.
    Copy the generated app ID and app secret ID, and save them to the basic settings section (Figure 5-26).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig26_HTML.jpg
    Figure 5-26

    Copy and save the app ID and app secret ID

     
  3. 3.
    Select the Advanced option and move the Allow API Access to App Settings slider to Yes (Figure 5-27).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig27_HTML.jpg
    Figure 5-27

    Allow API access

     
  4. 4.
    Then, enable Facebook Messenger in the new Facebook app by clicking Set Up in the Messenger blade (Figure 5-28).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig28_HTML.jpg
    Figure 5-28

    Enable Facebook Messenger

     
  5. 5.
    Under Settings, in the Token Generation screen, select the target page to generate an access token (Figure 5-29). Copy the token and save it temprorily, so that it can used in Figure 5-34.
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig29_HTML.jpg
    Figure 5-29

    Access token for Facebook app

     
  6. 6.
    To enable Webhooks to forward messaging events from Facebook Messenger to your chatbot, click Setup Webhooks (Figure 5-30).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig30_HTML.jpg
    Figure 5-30

    Set up Webhooks

     
  7. 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).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig31_HTML.jpg
    Figure 5-31

    Callback URL and verification token for Facebook

     
For a Webhook to subscribe to the Facebook page, go to the Facebook page and copy and paste the callback URL and the verification token for the Facebook values in New Page Subscription. In Subscription Fields, select messages, message_deliveries, messaging_postbacks, and messaging_options. Click Verify and Save (Figure 5-32).
../images/478917_1_En_5_Chapter/478917_1_En_5_Fig32_HTML.jpg
Figure 5-32

New-page subscription setup

  1. 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).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig33_HTML.jpg
    Figure 5-33

    Subscribe Webhooks to the Facebook page

     
  2. 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.

     
../images/478917_1_En_5_Chapter/478917_1_En_5_Fig34_HTML.jpg
Figure 5-34

Enter Facebook Messenger credentials

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

To connect a chatbot with a workplace Facebook account, you need to create a custom integration:
  1. 1.
    Click the Admin Panel tab of Facebook at Workplace. Click Integrations and then click Create Custom Integration (Figure 5-35).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig35_HTML.jpg
    Figure 5-35

    Go to the Admin Panel of Facebook at Workplace, click Open Integration, and click the Create Custom Integration.

     
  2. 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).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig36_HTML.jpg
    Figure 5-36

    In the workplace app, save the the app ID, app secret ID, and the app token.

     
  3. 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 .
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig37_HTML.jpg
    Figure 5-37

    Chatbot in a workplace community

     
  4. 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. 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

To connect a chatbot to GroupMe, do the following:
  1. 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).
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig38_HTML.jpg
    Figure 5-38

    Complete the GroupMe application

     
  2. 2.
    Copy your client ID in Redirect URL and your access token as shown in Figure 5-39 .
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig39_HTML.jpg
    Figure 5-39

    Update credentials

     
  3. 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.
    ../images/478917_1_En_5_Chapter/478917_1_En_5_Fig40_HTML.jpg
    Figure 5-40

    Readying the chatbot for publication

     

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.254.90