在使用Microsoft bot框架的Microsoft团队中显示欢迎消息
我已使用以下代码向用户显示欢迎消息.
I have used below code for showing a welcome message to user.
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)
{
string replyMessage = string.Empty;
replyMessage = Responses.Greeting;
return message.CreateReply(replyMessage);
}
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;
}
如果活动类型不是消息,则下面的方法用于调用HandleSystemMessage.
Below method is used to call HandleSystemMessage, if activity type is not message.
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
string reply = "";
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
if (activity.Type == ActivityTypes.Message)
{
stLuis = await LuisHelper.ParseUserInput(activity.Text);
string userResponse = activity.Text.ToLower();
switch (stLuis.topScoringIntent.intent)
{
case "Greetings":
reply = Responses.Greeting;
break;
case "None":
reply = Responses.None;
break;
default:
break;
}
}
if (reply != "")
await connector.Conversations.ReplyToActivityAsync(activity.CreateReply(reply));
}
else
{
var reply1 = HandleSystemMessage(activity);
if (reply1 != null)
await connector.Conversations.ReplyToActivityAsync(reply1);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
此代码适用于Skype.但是,当我在Microsoft团队中添加相同的漫游器时,它不会显示欢迎消息.
This code works with Skype. But when I add same bot in Microsoft teams, it doesn't show a welcome message.
到现在(2016-12-30)当您将漫游器添加到联系人列表"时,MSFT团队根本不会发送任何消息.正如MSFT的专家所说,这是一个已知的局限性,将在不久的将来解决.
By now (2016-12-30) MSFT Teams does not send any message at all when you add a bot to "contact list". This is a known limitation and to be addressed in the nearest future, as MSFT guys say.
与此同时,要向机器人获取ConversationUpdate消息,用户必须首先启动与机器人的对话.
In the meantime to get a ConversationUpdate message to the bot, the user will have to first initiate a conversation with the bot.
作为一种解决方法,如果您的漫游器足够有状态,则可以处理用户发送的特殊文本,例如开始",或者仅处理第一个传入的消息.
As a workaround you can handle special text sent from user, like "start", or just the very first incoming message, if your bot is stateful enough.