{"id":1340,"date":"2018-04-26T01:39:44","date_gmt":"2018-04-26T08:39:44","guid":{"rendered":"https:\/\/officedevblogs.wpengine.com\/?p=1340"},"modified":"2021-09-23T14:03:26","modified_gmt":"2021-09-23T21:03:26","slug":"adding-bot-support-to-a-kaizala-group","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/adding-bot-support-to-a-kaizala-group\/","title":{"rendered":"Adding bot support to a Kaizala group"},"content":{"rendered":"<p>In this post, I&#8217;ll explore on how you can integrate a bot with a Kaizala group. Bot aids a lot of scenarios and can be a part of the conversations and adding value. In a regular group, the messages are received and seen by all users, and can result in a chatty experience. Public groups (managed hub and spoke groups) are well suited for this scenario where the user or subscriber types in a query allowing a bot to respond \u2013 while keeping these out of the purview of other users in the group. In order to implement this, following are the steps that will take you through this experience.<\/p>\n<ol>\n<li>Enabling text messaging in a Public group<\/li>\n<li>Registering WebHook for TextMessageCreated event<\/li>\n<li>Configuring bot user in the group<\/li>\n<li>Replying to user input as a bot<\/li>\n<\/ol>\n<h2>Step-1: Enabling text messaging in public group<\/h2>\n<p>By default, in a managed hub &amp; spoke group, text messaging is disabled (to avoid chattiness). However, we could flip a group policy to enable text messages. However, only admins would received these messages \u2013 allowing them to be processed by a bot.<\/p>\n<h3>1.1) Fetching group policies applied to the group<\/h3>\n<p>In order to remove the policy that restricts text, lets query the policies applied on the group (illustrated below). Notice the\u00a0<strong>policyTextRestricted<\/strong>\u00a0in the policy returned.<\/p>\n<p><img decoding=\"async\" class=\"size-full wp-image-1341\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/1get-group-policy.png\" alt=\"fetch-group-policies-applied-to-the-group\" width=\"912\" height=\"743\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/1get-group-policy.png 912w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/1get-group-policy-300x244.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/1get-group-policy-768x626.png 768w\" sizes=\"(max-width: 912px) 100vw, 912px\" \/><\/p>\n<h3>1.2) Removing text restriction from policy<\/h3>\n<p>To remove the text message restriction, we will apply all the policies barring the group policy \u2013\u00a0<strong>policyTextRestricted. <\/strong>This is illustrated in the following screenshot.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1342\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/1.2set-group-policy.png\" alt=\"set-group-policy\" width=\"803\" height=\"423\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/1.2set-group-policy.png 803w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/1.2set-group-policy-300x158.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/1.2set-group-policy-768x405.png 768w\" sizes=\"(max-width: 803px) 100vw, 803px\" \/><\/p>\n<h2>Step-2: Registering WebHook for TextMessageCreated event<\/h2>\n<p>Once you have the text message enabled for subscribers, they will be able to send text messages. You will need to register a WebHook to tap into the text messages being sent \u2013 for which you will need to subscribe to the TextMessageCreated event.<\/p>\n<p>In the interest of keeping this post short, I will not revisit WebHooks here \u2013 it has been covered in\u00a0<a href=\"https:\/\/kaizala007.blog\/2017\/12\/30\/exploring-kaizala-webhooks\/\">Exploring Kaizala WebHooks<\/a>.<\/p>\n<h2>Step-3: Configuring bot user in the group<\/h2>\n<p>Once you start receiving the text message from the subscriber(s), you will need to respond to them. You could choose to respond to them as the admin user itself \u2013 in which case:<\/p>\n<ul>\n<li>It will be difficult to identify that the message \/ response was from a system<\/li>\n<li>People could ping the admin with queries<\/li>\n<\/ul>\n<p>In order to avoid these, you could create a bot user with a name and profile pic \u2013 using which you could respond to the queries.<\/p>\n<p>Bot user APIs have been documented in Microsoft Kaizala Postman API collection. To view, click the\u00a0<strong>Run in Postman<\/strong>\u00a0button from\u00a0<a href=\"https:\/\/docs.microsoft.com\/en-us\/kaizala\/connectors\/api\">the Kaizala API documentation<\/a>].<\/p>\n<h2><img decoding=\"async\" class=\"alignnone size-full wp-image-1343\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3bot-user-postman-collection.png\" alt=\"bot-user-postman-collection\" width=\"401\" height=\"230\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3bot-user-postman-collection.png 401w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3bot-user-postman-collection-300x172.png 300w\" sizes=\"(max-width: 401px) 100vw, 401px\" \/><\/h2>\n<h2>3.1) Creating a bot user<\/h2>\n<p>To create a bot user, we will need to post to the\u00a0<strong>v1\/bot<\/strong>\u00a0endpoint. On success, you would get a botUserId in the response.<\/p>\n<div>\n<table title=\"\" border=\"1\" summary=\"\" width=\"428\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<p lang=\"en-IN\">METHOD<\/p>\n<\/td>\n<td>\n<p lang=\"en-IN\">POST<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p lang=\"en-IN\">URL<\/p>\n<\/td>\n<td>\n<p lang=\"en-IN\">{{endpoint-url}}\/v1\/bot<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p lang=\"en-IN\">REQUEST BODY<\/p>\n<\/td>\n<td>\n<p lang=\"en-IN\">{<\/p>\n<p lang=\"en-IN\">\u201cname\u201d:\u201d&lt;&lt;bot user name&gt;&gt;\u201d,<\/p>\n<p lang=\"en-IN\">\u201cprofilePic\u201d:\u201d&lt;&lt;Media resource string of profile pic&gt;&gt;\u201d<\/p>\n<p lang=\"en-IN\">}<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1344\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.1create-bot-user.png\" alt=\"create-bot-user\" width=\"845\" height=\"473\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.1create-bot-user.png 845w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.1create-bot-user-300x168.png 300w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.1create-bot-user-768x430.png 768w\" sizes=\"(max-width: 845px) 100vw, 845px\" \/><\/p>\n<h2>3.2) Adding the bot user to the group<\/h2>\n<p>To add a bot user to the group, we will need to post to the\u00a0<strong>v1\/groups\/{{group-id}}\/bot<\/strong>\u00a0endpoint with the botUserId generated in step 3.1.<\/p>\n<div>\n<table title=\"\" border=\"1\" summary=\"\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<p lang=\"en-IN\">METHOD<\/p>\n<\/td>\n<td>\n<p lang=\"en-IN\">POST<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p lang=\"en-IN\">URL<\/p>\n<\/td>\n<td>\n<p lang=\"en-IN\">{{endpoint-url}}\/v1\/groups\/{{group-id}}\/bot<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p lang=\"en-IN\">REQUEST BODY<\/p>\n<\/td>\n<td>\n<p lang=\"en-IN\">{<\/p>\n<p lang=\"en-IN\">\u201cbotUserId\u201d:\u201d&lt;&lt;bot user id&gt;&gt;\u201d<\/p>\n<p lang=\"en-IN\">}<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1345\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.2add-bot-user-to-group.png\" alt=\"add-bot-user-to-group\" width=\"574\" height=\"223\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.2add-bot-user-to-group.png 574w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.2add-bot-user-to-group-300x117.png 300w\" sizes=\"(max-width: 574px) 100vw, 574px\" \/><\/p>\n<h3>3.3) Generating access-token for the bot user<\/h3>\n<p>To generate access-token for the bot user, we will need to do a GET to the\u00a0<strong>v1\/bot\/accessToken\/{{bot-user-id}}<\/strong>\u00a0endpoint.<\/p>\n<div>\n<table title=\"\" border=\"1\" summary=\"\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td>\n<p lang=\"en-IN\">METHOD<\/p>\n<\/td>\n<td>\n<p lang=\"en-IN\">GET<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p lang=\"en-IN\">URL<\/p>\n<\/td>\n<td>\n<p lang=\"en-IN\">{{endpoint-url}}\/v1\/bot\/accessToken\/{{bot-user-id}}<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1346\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.3generate-bot-access-token.png\" alt=\"generate-bot-access-token\" width=\"620\" height=\"437\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.3generate-bot-access-token.png 620w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/3.3generate-bot-access-token-300x211.png 300w\" sizes=\"(max-width: 620px) 100vw, 620px\" \/><\/p>\n<p>Note: The accessToken used in the header for steps 3.1, 3.2 and 3.3 are the access token that belong to the group admin. Only from the next step will we be using the accessToken of the bot user.<\/p>\n<h2>Step-4: Replying to user input as a bot<\/h2>\n<p>Now, using the token generated in step 3.3, you could send a message (or attachment \/ action) \u2013 but with the accessToken of the bot. When it appears for the subscriber, it would appear with the test bot\u2019s name.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1347\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/4send-message-to-subscriber-1.png\" alt=\"send-message-to-subscriber\" width=\"607\" height=\"287\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/4send-message-to-subscriber-1.png 607w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/4send-message-to-subscriber-1-300x142.png 300w\" sizes=\"(max-width: 607px) 100vw, 607px\" \/><\/p>\n<p>Sample screenshot of the message received on phone:<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1349\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/4.1message-from-bot.jpg\" alt=\"message-from-bot\" width=\"394\" height=\"137\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/4.1message-from-bot.jpg 394w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/4.1message-from-bot-300x104.jpg 300w\" sizes=\"(max-width: 394px) 100vw, 394px\" \/><\/p>\n<p>Tapping on the bot name, (<strong>GLS test bot1<\/strong>\u00a0here), opens up a contact card for the bot that looks like this (name and profile pic used while creating bot in step-1):<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-1350\" src=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/4.2bot-profile.jpg\" alt=\"bot-profile-image\" width=\"267\" height=\"344\" srcset=\"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/4.2bot-profile.jpg 267w, https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-content\/uploads\/sites\/73\/2018\/06\/4.2bot-profile-233x300.jpg 233w\" sizes=\"(max-width: 267px) 100vw, 267px\" \/><\/p>\n<p>Hope that was helpful, do let me know of what you think through the comments. Thank you for reading!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I&#8217;ll explore on how you can integrate a bot with a Kaizala group. Bot aids a lot of scenarios and can be a part of the conversations and adding value. In a regular group, the messages are received and seen by all users, and can result in a chatty experience. Public groups (managed hub and spoke groups) are well suited for this scenario where the user or subscriber types in a query allowing a bot to respond \u2013 while keeping these out of the purview of other users in the group. In order to implement this, following are the steps that will take you through this experience.<\/p>\n","protected":false},"author":69216,"featured_media":1350,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11],"tags":[87,37],"class_list":["post-1340","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-office-add-ins","tag-kaizala","tag-bot-framework"],"acf":[],"blog_post_summary":"<p>In this post, I&#8217;ll explore on how you can integrate a bot with a Kaizala group. Bot aids a lot of scenarios and can be a part of the conversations and adding value. In a regular group, the messages are received and seen by all users, and can result in a chatty experience. Public groups (managed hub and spoke groups) are well suited for this scenario where the user or subscriber types in a query allowing a bot to respond \u2013 while keeping these out of the purview of other users in the group. In order to implement this, following are the steps that will take you through this experience.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/1340","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/users\/69216"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/comments?post=1340"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/posts\/1340\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media\/1350"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/media?parent=1340"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/categories?post=1340"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/microsoft365dev\/wp-json\/wp\/v2\/tags?post=1340"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}