This is a very simple yet useful article. If you are new to learning bot framework, please follow my previous article.
When we launch any bot, asyncPost method is invoked on messagesController like below.
- public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
- {
- if (activity.Type == ActivityTypes.Message)
- {
- await Conversation.SendAsync(activity, () => new BingSearchDialog());
- }
- else
- {
- await HandleSystemMessage(activity);
- }
- var response = Request.CreateResponse(HttpStatusCode.OK);
- return response;
- }
In the above code, HandleSystemMessage method will be invoked by default.
- private async Task<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)
- {
- // Handle conversation state changes, like members being added and removed
- // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
- // Not available in all channels
- 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($"Hey Welcome to search chatbot.");
- await connector.Conversations.ReplyToActivityAsync(reply);
- }
- }
- }
- }
- 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;
- }

Join the conversation! Your thoughts help the community grow.
Sign in to leave a comment
It is the same account you read, post and publish with — and you will come straight back to this page.

Mounika PedapatiPosted Oct 12, 2018, 4:01 AM
Hi sir, How Can I send welcome message in short messages instead of single long message means if i want to send "welcome" in one message and "how can I help you" in another message instead of single message. I tried by giving two different messages in the above code but it is displaying only first message.