If you had read our post on how to post a message to a channel in a simple one-line command
, then this sure is a piece of cake for you guys! For those of you, who are reading this for the first time, don't worry! Just read on. This post is all about how to send a message to your bot and broadcast it to all your bot subscribers through a simple command.
We'll be looking at how to post a message to the bot using cURL, Wget and PowerShell. The steps are pretty straight forward. You'll need the following:
- Create a bot
- Generate a webhook token
- Form your message as a JSON
- Post your message to the bot's messaging endpoint
- And done
Get started by creating a bot
Get started with creating your bot, if you haven't already! You can refer our help page
on bot creation. Once you've created the bot, take note of the bot's endpoint URL in the bot preview page. You can find the bot preview page by following the below steps:
- Click on Settings and choose Integrations.
- Select Bots in the Integrations page.
- Select which ever bot you would like to send a message to and click on the bot's name. The bot's preview page is displayed.
Webhook tokens are unique authentication keys specific to a user. These tokens can be used to connect with third party applications through webhooks, in order to post messages to a channel or chat.
To use the Messaging API you'll need Cliq's webhook tokens.These tokens will provide you with authentication to access the message APIs. Follow the given steps to generate your own webhook:
- In Cliq, click on your profile in the top right corner and choose -> Bots & tools
- Now, in the integrations page click on Webhook tokens at the bottom left
- Click on the button Generate new token to generate your webhook token
To know more about webhooks click on the following link:
Structure your message as a JSON
We have an easy way to build cool message card templates. The message structure shown below is built using our Message Builder
. Here, we're trying to notify all the bot's subscribers. This can be done using the broadcast
parameter. When broadcast is true, message is posted to all subscribers of the bot! More details about this parameter and the other parameters are explained in our How to post message to a bot
And finally, posting the message!
We'll be sending the message through a standard POST request.
Take a look at how to make the request via curl :
Similarly, the same request using Wget :
Finally, PowerShell for all you Windows people out there!
How about trying these right away? All you've to do is replace the webhook token with yours and give your bot's unique name in the script. Get started now and tell the world how easy it indeed is! Comments and suggestions are welcome.