I am developing a project where a bot has to talk to another bot on slack and make it execute some tasks. I wanted to know if there is an api or something by which I can post the message from one bot to another using node js. One of which is dmy bot is service now virtual-agent. How can we make the virtual agent of service now listen to my main bot,which is made of dialogflow.
1 Answers
You can retrieve all messages posted on a Slack workspace (within limits) by listening to message events via the Events API, e.g. message.channels to listen to all messages posted in public channels.
Message events include a full copy of the message, so you can then just forward that copy to another bot if you want, e.g. by adding a @bot mention and re-posting it in the same channel or sending a direct message to the other bot.
However - if the other bot will recognize the message from your bot depends a lot on how it's designed. Messages from users and bots usually look different and many bots will ignore messages that are not from a user.
Example message from user:
{
"team": "T1234567",
"text": "hi",
"ts": "1516240585.000208",
"type": "message",
"user": "U12345678"
}
Example message from bot:
{
"bot_id": "B12345678",
"subtype": "bot_message",
"text": "Hi",
"ts": "1516582987.000123",
"type": "message",
"username": "My Bot"
}
There is one exception. It's possible to create user message with the API that are indistinguishable from message posted on the client. Those should be picked up by another bot just as any message would.
Here is how:
- Use
chat.postMessage
for sending the message - Use the user token (aka Oauth Access Token) of your user (not a bot token) in the API call
- Set the API parameter
as_user
to true

- 30,467
- 8
- 79
- 114
-
one of my bots is the service now's virtual agent . Do you have any idea how to make service now virtual agent listen to messages in channels? – AVS Kasturi Karthik Jul 05 '19 at 04:38
-
I added how to send message via API that looks exactly like user messages and should be picked up the other bot – Erik Kalkoken Jul 05 '19 at 09:37