我想介绍我的BOT。当用户被添加到他们的对话/联系人列表中时。我已经尝试过处理ActivityTypes.ConversationUpdate消息类型。但它不适用于Skype。有什么共同的方法可以在所有渠道中运作。
这是我使用的代码:
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));
if (activity.Type == ActivityTypes.Message)
{
// calculate something for us to return
int length = (activity.Text ?? string.Empty).Length;
// return our reply to the user
Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
await connector.Conversations.ReplyToActivityAsync(reply);
}
else if(activity.Type == ActivityTypes.ConversationUpdate)
{
StateClient stateClient = activity.GetStateClient();
BotData userData = await stateClient.BotState.GetUserDataAsync(activity.ChannelId, activity.From.Id);
if (!userData.GetProperty<bool>("SentGreeting"))
{
Activity reply = activity.CreateReply($"Hi " + activity.From.Name + ", I'm the Microsoft Bot");
userData.SetProperty<bool>("SentGreeting", true);
await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);
await connector.Conversations.ReplyToActivityAsync(reply);
}
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
works here 提前谢谢。
答案 0 :(得分:2)
Skype
频道未发送ConversationUpdate
消息。 Bot Framework Emulator
和WebChat
等其他渠道都可以。在从Skype
频道收到用户的消息之前,没有办法向用户发送消息。