MessageBird: Deploy an Instagram Endpoint


"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

  1. Inside of Cognigy.AI: Create a REST Endpoint
  2. Inside of MessageBird: Setup the Instagram Channel
  3. Inside of MessageBird: Create a Flow
  4. Configure the Fetch Variables Function
  5. Configure the Reply to channel message Function
  6. 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:

  1. Login to Cognigy.AI and navigate to the virtual agent that should be connected to Instagram
  2. Navigate to Deploy -> Endpoints and click on the + New Endpoint button:


  3. 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
  4. Now, please scroll down in the list of possible Endpoints and select REST:


  5. Now, something like the following should be visible on the screen while the Endpoint URL will be used inside of MessageBird later:


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

  1. Login to the MessageBird Dashboard
  2. In the left side menu, navigate to Channels
  3. Please select Instagram in the list of provided channels with the headline "Add a new channel"
  4. Now, MessageBird will start the configuration process in order to connect an existing Instagram Business account
    1. Please follow the MessageBird documentation for a detailed explanation
  5. 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:

  1. Inside of the MessageBird Dashboard left side menu, please navigate to Flow Builder
  2. Create a new Flow or select the Default Flow that was configured by MessageBird automatically:


  3. Inside of this, three functions must be added in order to make this connection work:
    1. Omnichannel
      1. Takes the incoming Instagram Direct Message
    2. Fetch Variables
      1. Sends the message to the Cognigy.AI REST Endpoint and stores the response (text) into a variable
    3. Reply to channel message
      1. 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.


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:

  1. Inside of the MessageBird Flow, please open the Fetch Variables function in order to see the edit menu
  2. Paste the Cognigy.AI REST Endpoint URL to the URL field
  3. Scroll down and select POST in the Method field
  4. Scroll down and define the Body field with the following template JSON content:
    "userId": "",
    "sessionId": "",
    "text": "",
    "data": {
    "displayName": "",
    "phone": ""
    1. 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.
    2. 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:
      1. {{incomingMessage => this will add the incomingMessage variable to the JSON.
      2. Finally, the JSON should look such as the following:


    3. Last but not least, scroll down again in the edit menu and look for the Variables section.
      1. Please add a new Variable and call it "text":

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

  1. Inside of the MessageBird Flow, please open the Reply to channel message function in order to see the edit menu
  2. Select Text as Message Type
  3. Inside of the Content field, add the text variable that was created before inside of the Fetch Variables function
    1. {{text => this will add the text variable to the field
    2. The edit menu will look such as the following now:


  4. Click Save

Test the connection

Open the Instagram app on a mobile phone or open the 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".








Article is closed for comments.

Was this article helpful?
0 out of 0 found this helpful