Can a slack bot message another bot? - bots

I have a bot, and I can interact with it. And there's another bot, and I would like my bot to chat with that bot, when they are in the same channel. Is that even possible?
I tried to include a mention like <#IDBOT|name>: text, and even though it appears to me that the mention was successful, the other bot doesn't respond. If I post this mention it will work.
Is there a limitation here?

Yes, it can.
I had the same problem, it turns out that I had included some code that I didn't understand, and that code was preventing the response. I e-mailed slack about it and they set me straight.
The problematic code was this:
if event["type"] == "message" and not "subtype" in event:
user_id, message = parse_direct_mention(event["text"])
if user_id == self_id:
return message, event["channel"]
The helpful response from slack:
The condition below is what's preventing your bot from listening to bot's messages:
if event["type"] == "message" and not "subtype" in event:
When a message is sent by a bot, it will have a subtype, so this means that your logic is disregarding any bot message.
This is helpful because it prevents your bot from responding to its own messages, which would create an infinite loop.
You'll need to modify this condition so that your bot still "ignores" its own messages, but processes messages from other bots. You could do this for instance by looking at the bot ID or user ID and discarding those messages, but not messages from other bots.
In my case, I want the bot to respond to humans always, and bots only if they are trusted, so I did this:
from_user = "subtype" not in event
from_friend_bot = (event["subtype"] == "bot_message") and (event['username'] == f'{ping_source}')
if from_user or from_friend_bot:
user_id, message = parse_direct_mention(event["text"])
if user_id == self_id:
return message, event["channel"]

Yes, bots can talk to each other in a channel.
It depends on how you control the listening bot. I'm using a fork of the official Python Slackbot code (https://github.com/bscan/python-slackbot) and in it, I check for <#U1234567> where U1234567 is the user_id of the bot. When you mention #mybot, Slack replaces #mybot with <#U1234567> in the message. However, when posting as a bot, Slack doesn't replace a callout with the user_id. Instead, a bot can directly put <#U1234567> in the message (and post using as_user=True). Slack will display <#U1234567> as #mybot in the channel and the bot will be able to detect it if looking for that exact message string.
Source: played around until bots talked to each other.

Related

I can't seem to find a way to make my discord bot send a message after being invited to a server

So, when I was making my bot project, I wanted to add a feature in which sends a message after being invited to a server, as a way of thanking the owner for the invitation, however, I cannot seem to find a way to get this since most of the solutions are outdated, due to the version of the library. Any suggestions?
*User Invites the bot*
Bot: "Thanks for inviting me blah blah blah"
You can use the guildCreate event, that gets triggered every time the bot joins a server, example:
client.on('guildCreate', guild => {
let channel = guild.channels.cache.first();
if(channel) channel.send('Hey!');
}
In this example we get a random channel from the guild and send a message in it, you might also check if the bot has the permission to send messages.

Directline API message to Microsoft Bot

I have created the bot in azure services using LUIS, which used as chatbot and can create conversations using dialogs.
At some point, I am trying to push messages to chatbot using Direct Line API 3.0, I'm using Postman to send the messages to bot.
I followed the instructions from this page, https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-send-activity?view=azure-bot-service-4.0
I'm able to send message to the conversation as bot, below is the image I sent message from Postman and got successful response.
But my issue is, after the message is sent, the bot tries to analyse even though it's not user message. Bot starts to send message from default message handler like below,
Even after sending the message successfully, my bot triggers the default message handler, which is expected only to happen for user messages but not for bot messages.
Also, I have checked with webchat channel, which it doesn't trigger this default message handler. This is happening only in DirectLine API, can anyone help me on this.
Instead of sending the message as type "message", you should send it as "event".
This way your MessagesController will see it as an ActivityType of Event instead of Message and you can process however you want without spaghettifying your actual message handling
If you want to send different kinds of event to make it even easier, then you can 'name' you event by supplying the 'name' field with a value in your json.
Third, if you need to include data with the message, you would supply a value in the 'value' field of your json.
The github page for the standard webchat client has some great information on sending events. It might shed a bit more light on the json.
You can read more about the 'event' activity type here
You message json would look something more like this:
{
"type": "event",
"from": {
"id": "user1"
},
"name": "theEvent",
"value": "someDataMyBotNeeds"
}

Botframework LUIS Slack bot only reply when name is mentioned

I'm creating a bot in slack using Microsoft's botframework and LUIS and in Node.js. Currently my bot will reply every time someone says something in the channel, however I want my bot to only reply when its name is mentioned in my slack channel. i.e. #my-bot do this
How would I approach this? Would I have to add slack api in order to do this?
One way I'm thinking is to create an entity to check for if #my-bot is mentioned, and if it is then reply and if not then don't. However, I feel there are better ways in doing this.
Thanks.
Edit:
dialog.onDefault(function (session) {
var msg = new builder.Message(session).entities();
console.log(msg);
console.log(session);
session.endDialog('Default Dialog');
});
I've looked through both msg and session and the Entities of both are empty.
I was able to use session.message.entities to use mentioned to know whenever the bot was mentioned.

How to build a slack bot to have multiple conversations?

I am building a slack bot using a third party service to handle responses based on inputs rather than just hard coding them into the bot. This service's API needs a client id & a conversation id to get the response. I found out that each time a slack bot receives a message, it creates a new message object each time so there isn't a way of keeping the clientID and conversation ID within the message object and have slack hold onto it.
rtm.on(RTM_EVENTS.MESSAGE, function(message // <-- new object each time the bot hears a message){
rtm.sendMessage('hello', message.channel);
});
So shortened down, does anyone know of a way to keep a conversation between a single user and the bot while holding onto some type of variable to hold the client and conversation ID?
You can store the message.user ID and track the conversation referring to that specific user. You will need to keep track of all ongoing conversations yourself. Something like this
rtm.on(RTM_EVENTS.MESSAGE, function(message // <-- new object each time the bot hears a message){
if(stored_conversations.indexOf(message.user) > -1){
//customize message depending on history
rtm.sendMessage('I remember you', message.channel);
}
});
Or, you could use Botkit - it manages bot-user conversations for you.

Is it possible to send the location from Telegram to Bot?

Is it possible to send the location from Telegram to Bot, which made in Bot Framework?
I send my location from my Telegram account to my Bot, but the server does not get them (I don't get the response).
Text messages send normal, and I get response from the server.
Code is very simple:
public async Task<Message> Post([FromBody]Message message)
{
return message.CreateReplyMessage("Tadaa");
}
Dang it, this is a bug. We are filtering out messages without content and we are not treating the location property as "content". To us it looks like no text, no attachments, no channeldata and so no reason to send the message. I will push through a fix.

Resources