Skip to content

Instantly share code, notes, and snippets.

@andz88
Created October 10, 2016 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andz88/750350af2ae7d6a67f797689e9dc6b0d to your computer and use it in GitHub Desktop.
Save andz88/750350af2ae7d6a67f797689e9dc6b0d to your computer and use it in GitHub Desktop.
using CrmChatBot.CRM;
using CrmChatBot.Model;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.FormFlow;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace CrmChatBot.FormFlow
{
public enum CarMakeOptions { Unknown, Honda, Toyota };
public enum CarModelOptions { Unknown, Jazz, City, CRV, Accord, HRV, Yaris, Corolla, Camry };
[Serializable]
public class CarInquiryFormFlow
{
public CarMakeOptions CarMake;
public CarModelOptions CarModel;
public string PreferredTime;
public string Name;
public string ContactNumber;
public static IForm<CarInquiryFormFlow> BuildForm()
{
OnCompletionAsyncDelegate<CarInquiryFormFlow> processRequest = async (context, state) =>
{
await context.PostAsync($@"Your test drive request summary:
{Environment.NewLine}Car Make: {state.CarMake.ToString()},
{Environment.NewLine}Car Model: {state.CarModel.ToString()},
{Environment.NewLine}Requested Time: {state.PreferredTime},
{Environment.NewLine}Customer Name: {state.Name},
{Environment.NewLine}Phone Number: {state.ContactNumber}");
var testDriveDetail = new TestDriveDetail
{
CarMake = state.CarMake.ToString(),
CarModel = state.CarModel.ToString(),
RequestedTime = state.PreferredTime,
CustomerName = state.Name,
PhoneNumber = state.ContactNumber
};
// save the data to CRM
CrmLead.CreateTestDrive(testDriveDetail, CrmDataConnection.GetOrgService());
};
return new FormBuilder<CarInquiryFormFlow>()
.Message("Welcome to the car test drive bot!")
.Field(nameof(CarMake))
.Field(nameof(CarModel))
.Field(nameof(PreferredTime))
.Field(nameof(Name))
.Field(nameof(ContactNumber))
.AddRemainingFields()
.Message("Thank you for your interest, your request has been logged. Our sales team will get back to you shortly.")
.OnCompletion(processRequest)
.Build();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment