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)
- {
-
-
- }
- else if (message.Type == ActivityTypes.ConversationUpdate)
- {
-
-
-
- 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 (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)
- {
-
-
- }
- else if (message.Type == ActivityTypes.Typing)
- {
-
- }
- else if (message.Type == ActivityTypes.Ping)
- {
- }
-
- return null;
- }
Output