Reputation: 524
When an ms bot is integrated into slack it works fine when replying to direct messages however if the bot is added to a channel it replies to every single message posted into the channel, rather than just messages like @myCustomBot 'this is my question'.
Is it possible to filter incoming messages into the bot so it only looks to reply to channel messages directed specifically to the bot?
So far its using the basic controller actions you get for a new bot project:
public async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
connector.Conversations.ReplyToActivityAsync(activity.CreateReply("hi there"));
//...
}
//...
}
Upvotes: 4
Views: 1130
Reputation:
So the logic would be this:
1) Test for when people are addressing bot directly;
2) Differentiate that depending on the channel.
public async Task<HttpResponseMessage> Post([FromBody] Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
if (activity.ChannelId === "slack") {
if (activity.Text.ToLower().StartsWith("@myCustomBot") {
return Request.CreateResponse(HttpStatusCode.OK); //quit
}
}
else if (activity.ChannelId === "facebook") {
//similar check, and if true, then:
//return Request.CreateResponse(HttpStatusCode.OK);
}
//otherwise, keep going:
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
connector.Conversations.ReplyToActivityAsync(activity.CreateReply("hi there"));
//...
}
//...
}
Upvotes: 2