当ms bot被集成到slack中时,它在回复直接消息时工作正常,但是如果将bot添加到频道,它会回复发布到频道中的每条消息,而不仅仅是@myCustomBot这样的消息’这是我的问题’.
是否有可能将传入的消息过滤到机器人中,因此它只能回复专门针对机器人的频道消息?
到目前为止,它使用了您为新的bot项目获得的基本控制器操作:
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"));
//...
}
//...
}
最佳答案 所以逻辑是这样的:
1)测试人们何时直接解决机器人问题;
2)根据频道区分.
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"));
//...
}
//...
}