Using Dialogs in Microsoft Bot Framework (Creating lead in CRM)


Let us continue with our previous post on Bot Framework

https://nishantrana.me/2017/04/18/getting-started-with-microsoft-bot-framework/

Here we will implement our own dialog.

Dialogs are basically a class which implements IDialog interface. Dialog sends a message to the user and is in suspended state till it waits for the response from the user. The state is saved in State Service provided by Bot Connector Service.

Here MyDialog is our dialog class which implements the IDialog Interface i.e. implement StartAsync method which would be the first method called. We also need to mark our class as Serializable.

Next we need to update our controller class to point it to our new MyDialog class.

Here we will ask the user about the product in which he is interested, then get the name and description and finally using this information we will create a Lead record inside CRM.

The lead record created in CRM.

Here we are making use of PromptDialog type for managing interactions with the user. Using PromptDialog we can easily prompt user for text, choice, attachment, confirmation etc.

The context here is the IDialogContext. In resume parameter, we can specify which dialog methods to be called next after the user has responded. The response from the user is passed to the subsequent dialog methods.


using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Connector;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Client;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Bot_Application1.Dialogs
{

public enum InterestOptions
{
Product1,
Product2,
Product3
}

// Decorate the class with Serializable attribute
[Serializable]
// Implement IDialog Interface
public class MyDialog : IDialog
{
InterestOptions interestOptions;
string name;
string description;

// Start Sysnc is the first method which is called
public async Task StartAsync(IDialogContext context)
{
await context.PostAsync("Hi how may i help you?");
// wait for the user's response
context.Wait(MessageRecieveAsync);
}

public virtual async Task MessageRecieveAsync(IDialogContext context, IAwaitable argument)
{
// get the message
var message = await argument;

if (message.Text.Contains("interested"))
{
PromptDialog.Choice(
context: context,
resume: ResumeGetInterest,
options: (IEnumerable<InterestOptions>)Enum.GetValues(typeof(InterestOptions)),
prompt: "Which product are your interested in :",
retry: "I didn't understand. Please try again.");
}

}

public async Task ResumeGetInterest(IDialogContext context, IAwaitable result)
{
interestOptions = await result;

PromptDialog.Text(
context: context,
resume: ResumeGetName,
prompt: "Please provide your name",
retry: "I didn't understand. Please try again.");
}

public async Task ResumeGetName(IDialogContext context, IAwaitable result)
{
name = await result;

PromptDialog.Text(
context: context,
resume: ResumeGetDescription,
prompt: "Please provide a detailed description",
retry: "I didn't understand. Please try again.");
}

public async Task ResumeGetDescription(IDialogContext context, IAwaitable result)
{
description = await result;
PromptDialog.Confirm(
context: context,
resume: ResumeAndConfirm,
prompt: $"You entered Product :- '{interestOptions}', Your Name - '{name}', and Description - '{description}'. Is that correct?",
retry: "I didn't understand. Please try again.");
}

public async Task ResumeAndConfirm(IDialogContext context, IAwaitable result)
{
bool confirm = await result;

if (confirm)
await context.PostAsync("Thanks for showing your interest we will contact you shortly.");

// Create a lead record in CRM
CreateLeadinCRM();

}

private void CreateLeadinCRM()
{
Microsoft.Xrm.Sdk.Entity lead = new Microsoft.Xrm.Sdk.Entity("lead");
lead.Attributes["subject"] = "Interested in product " + interestOptions;
lead.Attributes["lastname"] = name;
lead.Attributes["description"] = description;
GetOrganizationService().Create(lead);
}

public static OrganizationServiceProxy GetOrganizationService()
{
IServiceManagement<IOrganizationService> orgServiceManagement =
ServiceConfigurationFactory.CreateManagement<IOrganizationService>(new Uri("https://nishantcrm365.crm.dynamics.com/XRMServices/2011/Organization.svc"));

AuthenticationCredentials authCredentials = new AuthenticationCredentials();
authCredentials.ClientCredentials.UserName.UserName = "nishant@nishantcrm365.onmicrosoft.com";
authCredentials.ClientCredentials.UserName.Password = "*****";
AuthenticationCredentials tokenCredentials = orgServiceManagement.Authenticate(authCredentials);
return new OrganizationServiceProxy(orgServiceManagement, tokenCredentials.SecurityTokenResponse);
}
}

}

The next posts in this series

Hope it helps..

Configuring Live Assist (Preview) for Dynamics 365.


Let us see how we can configure Live Assist step by step.

First, go to Applications tab of the Dynamics 365 Administration Center.

Select Live Assist for Dynamics 365 and click on Manage.

Click on Accept to give permission to the app.

Select the Dynamics 365 Instance and provide your email id, accept the terms and conditions and click on Submit.

This configures the Live Assist on the specified Dynamics 365 Instance and also sends the email to the email id specified.

Once the configuration is done, we can see the new Live Assist section added in our Settings area.

There we can click on Admin URL of Live Assist for further configuration.

Clicking on it opens the Admin Center.

Click on Confirm and Authorize.

The Dashboard of the admin center.

The Get Started page.

Code Snippet that we can use to enable Live Assist in web site.

Live Assist adds a new panel on the right inside CRM.

To test it we can make use of Demo Site provided along with Live Assist.

The agent within CRM can click on Conversation Icon and “Grab a chat” to start conversation.

Now suppose we want to configure our CRM Portal to use it. For this we need to copy the code snippet provided earlier. Go to the Header web template of our Web Site and paste the JavaScript code to our Header’s source code.

This enables Live Assist in the portal.

Communication between the CRM user and the Portal user.

The helpful links and video

https://neilparkhurst.com/2017/04/09/cafex-live-assist-my-initial-install-with-usd/

https://blogs.technet.microsoft.com/lystavlen/2017/03/16/live-assist-for-dynamics-365-first-look/

Hope it helps..

Setting Regarding of a record in Automatic Record Creation and Update Rules in Dynamics 365


Hi,

While implementing a scenario i.e. automatic case creation on phone call create using Automatic Record Creation and Updating Rules, we found that whenever we were setting the Regarding Object in the Phone Call activity, the case record was not getting created.

Create Case Rule Item –

Creating a Phone Call record using Case as Regarding object.

Workflow ran but the case record was not created.

Then we created phone call activity record without setting the regarding object. This time workflow ran and created the case record.

Basically, the workflow creates the case record and updates the Regarding Object in the Phone call record with this newly created case record.

However, if we check the Official documentation

https://www.microsoft.com/en-us/dynamics/crm-customer-center/set-up-rules-to-automatically-create-or-update-records-in-dynamics-365-customer-service.aspx#bkmk_RuleAndQueues

we have this mentioned

However, in our case we created a phone call record with case as regarding object and had case as the entity selected in the Create Record step, in this case also the Action were not executed.

Hope it helps..

Unknown Error or Resource not found for the segment ‘msdyn_FpsAction’ in Schedule Board in Field Service in Dynamics 365.


Hi,

Recently we configured the portal trial instance and installed Partner Field Service portal in it .

However, while trying to access Field Service à Schedule Board, we were getting the below errors

Eventually it turned out that the issue was caused because of the certain processes being in draft state.

The post which helped in fixing this issue

https://glinks.co.uk/2017/01/06/field-services-schedule-board-unknown-error/

Hope it helps..

List of all blog posts on CRM and Azure Integration


 

Advertisements

Configure Product Recommendations using Recommendations API in Dynamics 365


For configuring Product Recommendations first we need to enable the preview –

Go to Settings – Administration – System Settings – Previews

Select Yes and Click on OK.

As a next step, we need to create Cognitive Services for Recommendation API and connect it to CRM.

Go to Portal

https://portal.azure.com

Search and select Cognitive Services Accounts

Click on Add

Select Recommendation API and provide other details and click on Create.

From Overview, note down the Endpoint which will be used to configure the connection in CRM.

From Keys, copy value of the Key which will be used for configuring connection to CRM.

In CRM, go to Settings – Administration and click on Azure Machine Learning Recommendation Service Configuration.

Specify the value for the URL and Key we had noted down earlier, save the record and click on Test Connection to test the connection.

On Successful connection, we’d see Success message for Last Connection Status. Click on Activate to enable the connection.

Now we need to define\build the model for recommendations. For this go to Settings – Product Catalog and click on Product Recommendations.

We’d see a recommendation model with default values

The model will have Basked Data Entities already defined. We can edit\add new\ delete these existing configuration records for Basked Data Entities. Basked Data Entities recommendations are based on which products appear together.

For e.g. in below Opportunity record we can see 27 inch and 12 inch monitor opportunity products appearing together. It will look for all such line items records.

Similarly we have recommendation entities records configured which we can update.

Once done with the configuration, we need to click on Build Model Version to build the model.

It will create a corresponding model version record.

We can check its progress by refreshing it.

Here the model that we had defined has successfully build and it took around 6 minutes.

We can click on the Model Version to open the record to get the further details.

Next step would be to check the recommendations. For this click on Test Recommendations.

Pop up opens wherein we can select the Products and model version and click on Show Result to see what are the product recommendations.

Once satisfied with the test result, click on Activate to enable the recommendations.

We might get the below message in case we do not have good enough data in our system.

To see it in action, open an existing opportunity record , go to product sub grid and select a product and select Suggest Products.

A dialog box opens up that shows the Cross-Sell products and other details.

Get all the details here

https://technet.microsoft.com/library/56b35229-72f8-46ca-bebf-eae023f633c2.aspx

Hope it helps..