public virtual async Task MessageReceivedAsync(IDialogContext context, IAwaitable <IMessageActivity> argument) { var message = await argument; var text = message.Text; // First detect the language for this conversation var userState = await CheckStatus.GetLanguageAsync(text); Helper.PushCultureForCurrentConversation(userState.Language); // Detect sentiment if any await CheckStatus.GetSentimentAsync(userState); // Save the user's state context.SaveUserState(userState); await context.PostAsync(Resources.Z_COG_BOT_WELCOME); await context.PostAsync(Resources.Z_COG_BOT_HOW_HELP_YOU); context.Wait(MessageReceivedAsync); }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { if (activity.Type == ActivityTypes.Message) { // await Conversation.SendAsync(activity, () => new ADetectingSentimentDialog()); ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); if (activity.Text.Equals("reset")) { await connector.Conversations.SendToConversationAsync(activity, activity.Conversation.Id); } // TODO : Test the starting language for the current conversation var userState = await CheckStatus.GetLanguageAsync(activity.Text); if (userState.Language.Equals("fr")) { Helper.PushCultureForCurrentConversation(userState.Language); await Conversation.SendAsync(activity, () => new RootLuisDialogFr()); } else if (userState.Language.Equals("en")) { Helper.PushCultureForCurrentConversation("en"); Activity reply = activity.CreateReply(Resources.USER_DLG_NOT_IMPLEMENTED); await connector.Conversations.ReplyToActivityAsync(reply); } else //other language { Helper.PushCultureForCurrentConversation("en"); Activity reply = activity.CreateReply(Resources.Z_COG_BOT_LANGUAGE_NOT_SUPPORTED); await connector.Conversations.ReplyToActivityAsync(reply); } } else { HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }