Using TBP API to send a message via a bot using Power Automate

Knowledge Level: Advanced

In this tutorial, we will demonstrate how you can use the TBP API to send a simple text message to a bot user via Power Automate.

Prerequisites:

Step 1: Extract Bearer token

If you have followed the guide to setup a bearer token for authentication (linked in the Prerequisites), you will notice that the bearer token appears in the output body of the 'HTTP' flow. We will need to separate the bearer token from the rest of the output.

We need to add a couple of modules to be able to separate the bearer token.

First, let's add an 'Initialize variable module' where we will store the bearer token when the flow is executed.

618

In the next step, add another module and look for 'Compose'. In this flow, we will use the output from the HTTP output body to extract the values under the variable 'access_token'.

610

In the 'Input' section of this module, enter the following code:

@{outputs('HTTP')?['BODY']?['access_token']}

After this, we will add one more module to store the extracted token value in the 'bearer token' variable we created above. To do this, look for the 'Set Variable' module and use the output from the 'Compose' module.

1012

Step 2: Send message to the bot user using HTTP module

In the last step, we will now add an 'HTTP' module to post our message to the bot user.

In the HTTP module settings, set the following:

Method: Post
URI: https://api.thebotplatform.com/v1.0/activity/external
Headers-Accept: application/json
Headers-Authorization: Bearer (bearer token value)

In the 'body' part, use the following code:

{
  "data": {
    "attributes": {
      "messages": [
        {
          "text": "Hello"
        },
        {
          "text": "World"
        }
      ],
      "recipient": "[email protected]"
    },
    "type": "external-activity"
  }
}

๐Ÿ“˜

Note

In the recipient section of the code, use the email address of the recipient who is supposed to receive this message.

The final configuration should look like this:

600

Once the above is completed, make sure to save your flow and turn it on.

If everything works as expected, you should receive a message from the bot once you run the trigger.

866