botframework - 如何使用 Microsoft bot 框架 SDK3 C# 在 Microsoft 团队中显示欢迎消息
问题描述
据此,在去年使用 ActivityTypes.ConversationUpdate 时,似乎不可能在 Microsoft 团队中显示欢迎消息。
我想知道现在是否可以。有什么建议吗?
我已经尝试过了,但它似乎不起作用。
private Activity HandleSystemMessage(Activity message)
{
if (message.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
if (message.Conversation.IsGroup == true)
{
bool addedBot = false;
Activity newMessage = new Activity();
string res = "";
for (int i = 0; i < message.MembersAdded.Count; i++)
{
if (message.MembersAdded[i].Id == message.Recipient.Id)
{
addedBot = true;
break;
}
}
if (message.MembersAdded.Count > 0 && addedBot == false)
{
ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
Activity reply = message.CreateReply("test");
connector.Conversations.ReplyToActivityAsync(reply);
}
}
else
{
ConnectorClient connector = new ConnectorClient(new Uri(message.ServiceUrl));
Activity reply = message.CreateReply("test");
connector.Conversations.ReplyToActivityAsync(reply);
}
}
else if (message.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
// Activity.From + Activity.Action represent what happened
}
else if (message.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
//else if (message.Type == ActivityTypes.Ping)
//{
//}
return null;
}
2018/09/06
有用。
解决方案
我的代码有效。但是,添加 bot 后似乎不可能向其他现有用户发送1to1 消息。
推荐阅读
- python - 消息类型 websocket.group_send 没有处理程序,如何解决?
- flutter - 如何剪裁圆形?
- python - (1e18+1)(1e18)/(1e18) 的除法在 Python 3.6 中给出 (1e18)
- flutter - 我可以使用 Dart web 包颤振项目吗?
- sql - 使用视图或表中的列插入/更新一列空值
- tornado - 如何在 tornado.wsgi 中修复“TypeError:__call__() 需要 2 个位置参数,但给出了 3 个”?
- swift - 如何用swift将屏幕分成3个梯形按钮?
- typescript - 泛型数组
- javascript - 如何在打字稿中对数组内的总价格求和并在角度7中调用它
- python - RuntimeError: LookupError: KeyError: No devices found for ----->Device Address: b200