I created one chatbot in Asp.net core using c#, I am facing issue regarding welcome message when the user opens chatbot the first time. it is working fine when I use Microsoft bot framework emulator. but when I create bot service in azure bot option then it is not through a welcome message. but yes, when you type anything and press send button after that it is displayed a welcome message. Means, azure bot receive any message then it responds but I want to display my welcome message first when the user open chat bot panel. any idea what is the solution in it?
i used this code, it is working fine in local bot framework emulator, but not in azure bot.
namespace Microsoft.BotBuilderSamples
{
public class DialogAndWelcomeBot<T> : DialogBot<T> where T : Dialog
{
public DialogAndWelcomeBot(ConversationState conversationState, UserState userState, T dialog, ILogger<DialogBot<T>> logger)
: base(conversationState, userState, dialog, logger)
{
}
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)
{
var replyOne = MessageFactory.Text($"Hi there! I'm bot. ");
await turnContext.SendActivityAsync(replyOne, cancellationToken);
var replyTwo = MessageFactory.Text($"How may i assist you?");
await turnContext.SendActivityAsync(replyTwo, cancellationToken);
}
}
}
}
}
You can refer this Code. It will help you.
IConversationUpdateActivity iConversationUpdated = message as IConversationUpdateActivity;
if (iConversationUpdated != null)
{
ConnectorClient connector = new ConnectorClient(new System.Uri(message.ServiceUrl));
foreach (var member in iConversationUpdated.MembersAdded ?? System.Array.Empty<ChannelAccount>())
{
// if the bot is added, then
if (member.Id == iConversationUpdated.Recipient.Id)
{
var reply = ((Activity)iConversationUpdated).CreateReply(
$"Hello Bot");
connector.Conversations.ReplyToActivityAsync(reply);
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.