"In 2019, there were almost 815 million users who accessed photo-sharing platform Instagram on a monthly basis. In 2023, [...] projected to reach nearly 1.2 billion users, as the most recent forecast suggests." (Statista, 2022)
This tutorial will explain how to connect a Cognigy.AI virtual agent to an Instagram business account in order to automatically respond to direct user messages. In this case, the provider MessageBird is used for connecting the Instagram channel via a REST Endpoint inside of Cognigy.AI.
Table of Contents
- Inside of Cognigy.AI: Create a REST Endpoint
- Inside of MessageBird: Setup the Instagram Channel
- Inside of MessageBird: Create a Flow
- Configure the Fetch Variables Function
- Configure the Reply to channel message Function
- Test the connection
Inside of Cognigy.AI: Create a REST Endpoint
Since there is only step to complete in Cognigy.AI, one can start with this one. Therefore, a new REST Endpoint must be created in the Virtual Agent:
- Login to Cognigy.AI and navigate to the virtual agent that should be connected to Instagram
- Navigate to Deploy -> Endpoints and click on the + New Endpoint button:
- Inside of the window that will open on the right side of the screen, please define the Name of the Endpoint and the Flow that should start the conversation
- Now, please scroll down in the list of possible Endpoints and select REST:
- Now, something like the following should be visible on the screen while the Endpoint URL will be used inside of MessageBird later:
- For now, we are done in Cognigy.AI
Inside of MessageBird: Setup the Instagram Channel
As the virtual agent is ready to take messages from Instagram through the REST connection, one can setup the Instagram channel inside of MessageBird:
- Login to the MessageBird Dashboard
- In the left side menu, navigate to Channels
- Please select Instagram in the list of provided channels with the headline "Add a new channel"
- Now, MessageBird will start the configuration process in order to connect an existing Instagram Business account
- Please follow the MessageBird documentation for a detailed explanation
- After finishing this process, one will find the Instagram channel under "My channels":
Inside of MessageBird: Create a Flow
Now, Instagram is connected to MessageBird so that human agents could use the MessageBird Inbox live chat tool for handling incoming contact requests. However, the Cognigy.AI virtual agent should handle those direct messages from users automatically -- instead of a human. Accordingly, all incoming Instagram direct messages must be forwarded to the Cognigy.AI REST Endpoint and send back the virtual agent's response to the Instagram user:
- Inside of the MessageBird Dashboard left side menu, please navigate to Flow Builder
- Create a new Flow or select the Default Flow that was configured by MessageBird automatically:
- Inside of this, three functions must be added in order to make this connection work:
- Omnichannel
- Takes the incoming Instagram Direct Message
- Fetch Variables
- Sends the message to the Cognigy.AI REST Endpoint and stores the response (text) into a variable
- Reply to channel message
- Sends the virtual agent's response to the Instagram Direct Chat. Finally, the user will see the message from the virtual agent in the chat window.
- Sends the virtual agent's response to the Instagram Direct Chat. Finally, the user will see the message from the virtual agent in the chat window.
- Omnichannel
Configure the Fetch Variables Function
In order to send the Instagram Direct Message to the Cognigy.AI virtual agent, the Fetch Variables function must be configured correctly. In this step, the Endpoint URL form the REST Endpoint (Cognigy) is used:
- Inside of the MessageBird Flow, please open the Fetch Variables function in order to see the edit menu
- Paste the Cognigy.AI REST Endpoint URL to the URL field
- Scroll down and select POST in the Method field
- Scroll down and define the Body field with the following template JSON content:
{
"userId": "",
"sessionId": "",
"text": "",
"data": {
"displayName": "",
"phone": ""
}
}- This data information will be sent to Cognigy.AI while the userId and sessionId define the current conversation. The text is the Instagram user message and data could define additional information that the virtual agent should use -- e.g. phone number and display name.
- In order to provide dynamic data, MessageBird provides variables that can be added by typing two curly brackets and then start typing the variable name:
- {{incomingMessage => this will add the incomingMessage variable to the JSON.
- Finally, the JSON should look such as the following:
- Last but not least, scroll down again in the edit menu and look for the Variables section.
- Please add a new Variable and call it "text":
- Please add a new Variable and call it "text":
- Click Save
Configure the Reply to channel message Function
Right now, the incoming Instagram message is taken by MessageBird and sent to the Cognigy.AI virtual agent through the REST connection while the response is stored into the "text" variable. The step is to send this dynamic virtual agent response back to the Instagram Direct Chat and, therefore, answer th user:
- Inside of the MessageBird Flow, please open the Reply to channel message function in order to see the edit menu
- Select Text as Message Type
- Inside of the Content field, add the text variable that was created before inside of the Fetch Variables function
- {{text => this will add the text variable to the field
- The edit menu will look such as the following now:
- Click Save
Test the connection
Open the Instagram app on a mobile phone or open the https://instagram.com website and start a Direct Chat with the configured Instagram Business account. As soon as a message is sent to this Instagram account, the Cognigy.AI virtual agent should answer with the first message of the selected Flow -- by default, it will be "Hello World".
Congratulations!
Comments
0 comments