public CallbackThing <List <int> > StartConversation(Action <ConversationFlow> script) { ConversationFlow = new ConversationFlow(); script(ConversationFlow); return(StartConversationInternal()); }
private async Task FillAnOrder(ConversationFlow flow, OrderInfo profile, ITurnContext <IMessageActivity> turnContext) { string input = turnContext.Activity.Text?.Trim(); string message; switch (flow.LastQuestionAsked) { case ConversationFlow.Question.None: await turnContext.SendActivityAsync("Let's get started. What is your name?"); flow.LastQuestionAsked = ConversationFlow.Question.Name; break; case ConversationFlow.Question.Name: if (OrderValidation.ValidateName(input, out string name, out message)) { profile.Name = name; await turnContext.SendActivityAsync($"Hi {profile.Name}."); await turnContext.SendActivityAsync("How old are you?"); flow.LastQuestionAsked = ConversationFlow.Question.Age; break; } else { await turnContext.SendActivityAsync(message ?? "I'm sorry, I didn't understand that."); break; }
/// <summary> /// This method will be called to get some initial information from the user prior to being proxied over to chime via directline /// </summary> /// <param name="flow"></param> /// <param name="profile"></param> /// <param name="turnContext"></param> /// <returns></returns> private static async Task FillOutUserProfileAsync(ConversationFlow flow, UserProfile profile, ITurnContext turnContext) { string input = turnContext.Activity.Text?.Trim(); string message; //This switch case will move based on an order of a conversation flow. Here I simply ask "What is your name?" and "What is your question?" //I will save those values to a sample profile class to be sent over directline. //Chime will interpret these values based off the ChannelAccount Class. switch (flow.LastQuestionAsked) { case ConversationFlow.Question.None: await turnContext.SendActivityAsync("Let's get started. What is your name?"); flow.LastQuestionAsked = ConversationFlow.Question.Name; break; case ConversationFlow.Question.Name: if (ValidateName(input, out string name, out message)) { profile.Name = name; await turnContext.SendActivityAsync($"Hi {profile.Name}."); await turnContext.SendActivityAsync("What can I help you with?"); flow.LastQuestionAsked = ConversationFlow.Question.Question; break; } else { await turnContext.SendActivityAsync(message ?? "I'm sorry, I didn't understand that."); break; }
private static async Task FillOutBookingDataAsync(ConversationFlow flow, BookingData data, ITurnContext turnContext, CancellationToken cancellationToken) { string input = turnContext.Activity.Text?.Trim(); var buttons = new List <CardAction>() { new CardAction() { Title = "ใช่", Type = ActionTypes.ImBack, Value = "ใช่" }, new CardAction() { Title = "ไม่", Type = ActionTypes.ImBack, Value = "ไม่ใช่" } }; switch (flow.LastQuestionState) { case ConversationFlow.QuestionState.None: await SendCardAsync(turnContext, buttons, cancellationToken); flow.LastQuestionState = ConversationFlow.QuestionState.IsAcceptBooking; break; case ConversationFlow.QuestionState.IsAcceptBooking: if (turnContext.Activity.Text == "ใช่") { await turnContext.SendActivityAsync("โปรดใส่รหัสพนักงานของคุณ"); flow.LastQuestionState = ConversationFlow.QuestionState.EmployeeId; } else { await SendCardAsync(turnContext, buttons, cancellationToken); } break; case ConversationFlow.QuestionState.EmployeeId: if (!string.IsNullOrWhiteSpace(input)) { data.EmployeeId = input; flow.LastQuestionState = ConversationFlow.QuestionState.RoomNo; } else { await turnContext.SendActivityAsync("เกิดข้อผิดพลาดกับการกรอกรหัสพนักงาน กรุณากรอกอีกครั้ง"); } break; default: await turnContext.SendActivityAsync(data.EmployeeId); break; } }
private static async Task FillOutUserProfileAsync(ConversationFlow flow, UserProfile profile, ITurnContext turnContext, CancellationToken cancellationToken) { var input = turnContext.Activity.Text?.Trim(); string message; if (ValidateName(input, out var name, out message)) { profile.Name = name; await turnContext.SendActivityAsync($"Hi {profile.Name}.", null, null, cancellationToken); await turnContext.SendActivityAsync("Would you like to check out what we have online?", null, null, cancellationToken); }
private async Task StartQuestioningProcess(ConversationFlow conversationFlow, ObservationParams observationParams, ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { string input = turnContext.Activity.Text?.Trim(); string message = string.Empty; switch (conversationFlow.Question) { case Question.None: // Move to the next question conversationFlow.Question = Question.ObservationStartDateQuestion; await turnContext.SendActivityAsync("Enter observation Start-Date", null, null, cancellationToken); break; case Question.ObservationStartDateQuestion: observationParams.StartDate = DateTime.Parse(input); await turnContext.SendActivityAsync("And please observation End-Date", null, null, cancellationToken); // Move to the next question conversationFlow.Question = Question.ObservationEndDateQuestion; break; case Question.ObservationEndDateQuestion: observationParams.EndDate = DateTime.Parse(input); await turnContext.SendActivityAsync("Observation type", null, null, cancellationToken); conversationFlow.Question = Question.ObservationTypeQuestion; break; case Question.ObservationTypeQuestion: observationParams.ObservationType = input; string observationDataText = await _externalApiAgregetionService.GetObservarionText(_config.Value.ApiKey, observationParams.StartDate, observationParams.EndDate, turnContext, cancellationToken); await turnContext.SendActivityAsync(MessageFactory.Text(observationDataText, observationDataText), cancellationToken); await turnContext.SendActivityAsync("Observation type", null, null, cancellationToken); // Move to the first question conversationFlow.Question = Question.ObservationTypeQuestion; break; } }
internal void SendConversationFlow(ConversationFlow _conversationFlow) { var instance = GetInstanceName(); var url = "https://" + instance + ".service-now.com/api/now/table/u_chatbot_conversation_flow"; HttpClient client = new HttpClient(); client.BaseAddress = new Uri(url); //add basic authorization AddAuthorization(client); var json = JsonConvert.SerializeObject(_conversationFlow); var content = new StringContent(json, Encoding.UTF8, "application/json"); var response = client.PostAsync(url, content).Result; var obj = response.Content.ReadAsStringAsync(); }
protected override async Task OnMessageActivityAsync(ITurnContext <IMessageActivity> turnContext, CancellationToken cancellationToken) { // Conversation Flow Accessors state setup var conversationFlowAccessors = _conversationState.CreateProperty <ConversationFlow>(nameof(ConversationFlow)); ConversationFlow flow = await conversationFlowAccessors.GetAsync(turnContext, () => new ConversationFlow(), cancellationToken); // ObservationParams state setup var observationParamsAccessor = _userState.CreateProperty <ObservationParams>(nameof(ObservationParams)); ObservationParams observationParams = await observationParamsAccessor.GetAsync(turnContext, () => new ObservationParams(), cancellationToken); // Start question Process await StartQuestioningProcess(flow, observationParams, turnContext, cancellationToken); // Save data changes await _conversationState.SaveChangesAsync(turnContext, false, cancellationToken); await _userState.SaveChangesAsync(turnContext, false, cancellationToken); }
private static async Task FillOutFeedBackAsync(ConversationFlow flow, UserProfile profile, ITurnContext turnContext) { string input = turnContext.Activity.Text?.Trim(); string message; switch (flow.LastQuestionAsked) { case ConversationFlow.Question.Correct: await turnContext.SendActivityAsync($"You selected: Answer is Correct"); break; case ConversationFlow.Question.InCorrect: await turnContext.SendActivityAsync($"You selected: Answer is IN Correct"); break; } }
internal void SaveConversationFlow(ProcessModel ProcessSelected, string conversationId) { var count = 0; foreach (var r in ProcessSelected.Releases) { if (r.parameters_required) { foreach (var p in r.parameters) { if (p.required) { if (p.parmType.Contains("Object")) { foreach (var o in p.obj) { if (o.parmType.Contains("String[]")) { var repeatedArr = new List <ProcessParameters>(); foreach (var a in o.array) { var parmName = a.parmName; if (a.parmName != o.parmName) { parmName = o.parmName + '[' + a.parmName + ']'; } var _conversationFlow = new ConversationFlow { u_conversation_id = conversationId, u_release_id = r.sys_id, u_param_name = parmName, u_last_question_index = count, u_type = a.parmType, u_active = true, u_parent_id = a.parentId, u_is_object = true }; SendConversationFlow(_conversationFlow); count++; if (a.length > 1) { var lenght = 1; while (lenght < a.length) { _conversationFlow = new ConversationFlow { u_conversation_id = conversationId, u_release_id = r.sys_id, u_param_name = parmName, u_last_question_index = count, u_type = a.parmType, u_active = true, u_parent_id = a.parentId, u_is_object = true }; SendConversationFlow(_conversationFlow); count++; lenght++; repeatedArr.Add(a); } } } if (repeatedArr.Count > 0) { foreach (var ra in repeatedArr) { o.array.Add(ra); } } } else { var _conversationFlow = new ConversationFlow { u_conversation_id = conversationId, u_release_id = r.sys_id, u_param_name = o.parmName, u_last_question_index = count, u_type = o.parmType, u_active = true, u_parent_id = o.parentId, u_is_object = true }; SendConversationFlow(_conversationFlow); count++; } } } else if (p.parmType.Contains("String[]")) { var repeatedArr = new List <ProcessParameters>(); foreach (var a in p.array) { var parmName = a.parmName; if (a.parmName != p.parmName) { parmName = p.parmName + '[' + a.parmName + ']'; } var _conversationFlow = new ConversationFlow { u_conversation_id = conversationId, u_release_id = r.sys_id, u_param_name = parmName, u_last_question_index = count, u_type = a.parmType, u_active = true, u_parent_id = a.parentId, u_is_array = true, }; SendConversationFlow(_conversationFlow); count++; if (a.length > 1) { var lenght = 1; while (lenght < a.length) { _conversationFlow = new ConversationFlow { u_conversation_id = conversationId, u_release_id = r.sys_id, u_param_name = parmName, u_last_question_index = count, u_type = a.parmType, u_active = true, u_parent_id = a.parentId, u_is_array = true }; SendConversationFlow(_conversationFlow); count++; lenght++; repeatedArr.Add(a); } } } if (repeatedArr.Count > 0) { foreach (var ra in repeatedArr) { p.array.Add(ra); } } } else { //save the params var _conversationFlow = new ConversationFlow { u_conversation_id = conversationId, u_release_id = r.sys_id, u_param_name = p.parmName, u_last_question_index = count, u_type = p.parmType, u_active = true, u_parent_id = p.parentId }; SendConversationFlow(_conversationFlow); count++; } } } } } }