Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.47 KB | None | 0 0
  1. Our tech was able to provide a short tutorial on the matter: how to create a bot, how to configure it, how to send messages as a bot and other stuff. Word of advice: this is a very basic description of implementing a bot, without tackling topics like retrieving webhooks, working on webhooks, hosting an endpoint to which the data will be sent ← those topics however should be handled directly by developers responsible for creating a bot.
  2.  
  3. CREATING A BOT
  4.  
  5. First of all, you can create a bot with the use of our Configuration API v.3. To be more exact, with the use of create_bot_agent method described here → https://developers.livechatinc.com/docs/management/configuration-api/#create-bot-agent
  6.  
  7. While creating a bot, you can provide the details like name, avatar, concurrent chat limits, bot priority and other properties responsible for configuring an agent. What’s important here however is providing the details about the webhook that the bot will receive (the address to which LiveChat will send data and the type of webhooks that bot should listen to) → based on that, LiveChat will send the information to the provided webhook address, and those webhooks will carry, for example, messages sent by customers. Events like text messages are carried in the incoming_event webhook described here: https://developers.livechatinc.com/docs/management/configuration-api/#incoming_event
  8.  
  9. Also, the literature that is worth sending to a person who’d like to create his own bot and link it with LiveChat:
  10.  
  11. creating BOT agents at LiveChat: https://developers.livechatinc.com/docs/management/configuration-api/#methods ;
  12.  
  13. reading about webhooks available at LiveChat: https://developers.livechatinc.com/docs/management/configuration-api/#webhooks .
  14.  
  15. AUTHORIZING BOT AT LIVECHAT
  16.  
  17. Now that you have got your bot ready and configured, it is time to learn how to authorize the bot in LiveChat, so that you will be able to actually send messages to customers and our API will not reject it.
  18.  
  19. To authorize calls made by BOT, you need to generate theAgent’s API access token (bearer token in other words) with the appropriate scopes. This can be done by creating a new application in our Developers Console → assigning proper scopes to the app → providing details like Redirect URI → and finally Saving Changes. Here’s the link to the documentation that will guide you through the entire process: https://developers.livechatinc.com/docs/getting-started/authorization/#public-server-side-apps
  20.  
  21. IMPORTANT INFORMATION: the access_token will be generated for 8 hours, after which you will need to acquire a new code, with the use of refresh_token – everything is described here, including the steps provided above: https://developers.livechatinc.com/docs/getting-started/authorization/#public-server-side-apps . Also, if you would like to know which scopes should you assign to your app, here’s the link that will provide you with the description of scopes: https://developers.livechatinc.com/docs/messaging/agent-chat-api/#scopes
  22.  
  23. IMPORTANT INFORMATION 2: We know that the process of refreshing the token every 8 hours seems to be the pain in the eye and to counter the possible questions, we have this to say: we are working on the Personal Access Token mechanism that will not require to be refreshed every 8 hours. The mechanism is actually ready, but as we do not have the proper documentation yet, unfortunately, that is something that we are working on and that you should see it in the Authorization section of our documentation soon.
  24.  
  25. SENDING EVENTS AS BOT
  26.  
  27. After acquiring the access_token, you can now begin to send events (like text messages or rich messages) as bot, with the use of our Agent Chat API (the list of available methods is here: https://developers.livechatinc.com/docs/messaging/agent-chat-api/#methods) → We're not gonna describe the whole process of sending events, as this is a different topic, so we will assume that you already know how to send events. Because of that, we will focus on how to send events as BOT, so that our API will recognize them and display them as messages sent by BOT.
  28.  
  29. In order for events to be sent from the bot (in other words → to tell our API that an event like text message was sent by the bot and not by regular agent), you will have to remember to use the author_id in the payload that is sent to our API. This can be done, in case of sending events via webhook, by adding the X-Author-Id header to the request to our API. Here’s the example of how such request can look like this: https://pastebin.com/pWAikZ0u
  30.  
  31. Such request will make sure that the event sent to our API (in this case, the event is a message that will be sent to a customer) is sent by the BOT → here’s how it looks like: https://take.ms/yHXwE
  32.  
  33. And that’s it! Even though the bot is using the access_token generated by you, the messages are sent as they would really be sent by the bot itself.
  34.  
  35. And here is some worth-reading literature when it comes to sending events to our API:
  36.  
  37. events available at API: https://developers.livechatinc.com/docs/messaging/agent-chat-api/#events ;
  38.  
  39. methods that you can use when communicating with our API: https://developers.livechatinc.com/docs/messaging/agent-chat-api/#methods .
  40.  
  41. FEW ADDITIONAL COMMENTS
  42.  
  43. We believe that the thing that needs to be emphasized is the fact that when creating bot at LiveChat, the routing of chats is handled entirely by us, based on the round-robin rule and the bot priority (that can be set up during creation). So, for example, when the visitor will start a chat on a license, our API will use our routing mechanisms to determine to which agent (bots included) the chat will be automatically assigned. This information, together with the chat ID and other details, will be delivered to you with the use of the incoming_chat_thread webhook (described here: https://developers.livechatinc.com/docs/management/configuration-api/#incoming_chat_thread). Because of that, you would have to make sure that BOT will not reply to threads to which he is not assigned to (otherwise, it may happen that the BOT will reply to a chat to which a real agent is already assigned to and is already replying).
  44.  
  45. We know that this is a very basic description, but setting up the BOT from scratch, together with the backend configuration is a process that should be handled by the developer. Nevertheless, we hope that it will shed some light on how such a process is handled and what does it consist of. In case you have any questions, please let me know and just reply to this email.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement