我正在使用Ibot界面,但是欢迎消息发送了两次。 我使用了OnTurnAsync方法,当我调用MemberFyre属性时,似乎没有任何作用。
要发送欢迎消息,我需要这段代码:
if (turnContext.Activity.Type == ActivityTypes.ConversationUpdate && turnContext.Activity.MembersAdded.Count == 1)
{
userProfile.Welcome = true;
var reply = turnContext.Activity.CreateReply();
reply.Attachments = new List<Attachment>();
reply.Attachments.Add(getCard("Welcome"));
await turnContext.SendActivityAsync(reply);
}
答案 0 :(得分:1)
这可能会发生一些事情。
如果您使用的是较新的ActivityHandler,则可以使用:
localhost:8080/image
或者,如果您使用的是旧的活动处理程序:
protected override async Task OnMembersAddedAsync(IList<ChannelAccount> membersAdded, ITurnContext<IConversationUpdateActivity> turnContext, CancellationToken cancellationToken)
{
foreach (var member in membersAdded)
{
if (member.Id != turnContext.Activity.Recipient.Id)
{
userProfile.Welcome = true;
var reply = turnContext.Activity.CreateReply();
reply.Attachments = new List<Attachment>();
reply.Attachments.Add(getCard("Welcome"));
await turnContext.SendActivityAsync(reply);
}
}
}
WebChat不会像Emulator那样自动发送ConversationUpdate。 See this WebChat sample了解如何发送欢迎事件。
通过查看public async Task OnTurnAsync(ITurnContext turnContext, CancellationToken cancellationToken = default(CancellationToken))
{
if (activity.Type == ActivityTypes.ConversationUpdate)
{
if (activity.MembersAdded != null)
{
foreach (var member in activity.MembersAdded)
{
if (member.Name != "Bot" && member.Name != null)
{
userProfile.Welcome = true;
var reply = turnContext.Activity.CreateReply();
reply.Attachments = new List<Attachment>();
reply.Attachments.Add(getCard("Welcome"));
await turnContext.SendActivityAsync(reply);
}
}
}
}
[...]
是否始终可以确保它不会重复发送。 This sample可能会有帮助。