我已使用以下代碼向用戶顯示歡迎消息。在Microsoft團隊中使用Microsoft bot框架顯示歡迎消息
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,如果活動類型不是消息。
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。但是當我在微軟團隊中添加同樣的機器人時,它不會顯示歡迎消息。
你能分享調用HandleSystemMessage的代碼嗎?你有沒有檢查過你的機器人收到的活動的類型屬性,當用戶發起一個新的談話? –
@ SidUppal-MSFT我添加了調用HandleSystemMessage的代碼。正如你現在所看到的,只有當活動類型不是消息時,我才調用HandleSystemMessage。 – Akshay
確認您發現可靠交付對話更新活動類型的錯誤。我們正在調查。 –