Today, I wanted to implement greeting message to my chatbot when users enter chat. I looked to some tutorial and saw that it seems to be easy. The chatbot works when I run on WebChat on Microsoft Azure Bot Service. Here is the screenshot picture that show what I have done. In the first picture you can see I put code in ConversationUpdate activity, and when I run build.cmd command in terminal, it shows an error which you can see on the second picture. Have in mind that I am new into Microsoft Bot Service. Can anyone please tell me what am I doing wrong? Thank you
Asked
Active
Viewed 45 times
1 Answers
0
from your first image error message, it states that your 'Activity' is not defined. You should declare your Activity message
and replace with activity
.
Update your HandleSystemMessage method so it looks like the following:
private Activity HandleSystemMessage(Activity activity)
{
if (activity.Type == ActivityTypes.DeleteUserData)
{
// Implement user deletion here
// If we handle user deletion, return a real message
}
else if (activity.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
IConversationUpdateActivity update = activity;
var client = new ConnectorClient(new Uri(activity.ServiceUrl), new MicrosoftAppCredentials());
if (update.MembersAdded != null && update.MembersAdded.Any())
{
foreach (var newMember in update.MembersAdded)
{
if (newMember.Id != activity.Recipient.Id)
{
var reply = activity.CreateReply();
reply.Text = $"Welcome {newMember.Name}!";
client.Conversations.ReplyToActivityAsync(reply);
}
}
}
}
else if (activity.Type == ActivityTypes.ContactRelationUpdate)
{
// Handle add/remove from contact lists
}
else if (activity.Type == ActivityTypes.Typing)
{
// Handle knowing tha the user is typing
}
else if (activity.Type == ActivityTypes.Ping)
{
}
return null;
}

hongguan
- 520
- 2
- 12