IranCahtBot
V.I.P
Posts: 27
Joined: Sat Feb 25, 2017 7:36 pm

To pass Customer's Message and some parameters to a dialogue

Sat Jun 17, 2017 12:41 pm

Hello Dear sir,
I appreciate you in advance for your attention to this matter.
In my application is needed to pass Customer's Message and some parameters to a dialogue. I want to use these parameters in the intents. Would you please help me how I can do that.
For example:
var bot = new OscovaBot();
bot.Dialogs.Add(new AppDialog());
bot.Trainer.StartTraining();

…….
evaluationResult = bot.Evaluate("Please cancel my appointment",CustomerID);

In the intent:
Expression ("Please cancel my appointment")]
public void CancelAppointment (Context context, Result result, CustomerID)
{
Search in appointment table in a DB by CustomerID and cancel the appointment;
Text = "Dear" + Customre's name + "your appointment was canceled"
result.SendResponse(Text);
}
I thank you very much for taking time to answer my question and help me.

With regards
Ebrahimi

User avatar
Fantom
Help & Support
Posts: 320
Joined: Fri Oct 25, 2013 9:20 pm

Re: To pass Customer's Message and some parameters to a dial

Sat Jun 17, 2017 3:57 pm

Adding parameters to CreateRequest would be a very bad design practice thus OSCOVA has SharedData property on user context.

Firstly create some Data container class that can be shared for different users.

CSharp Code

public class SomeDataProvider
{
	public string CustomerId { get; set; }
}
//When you create a new user add the container class to the user context's shared data.

CSharp Code

var user = bot.CreateUser("Ebrahimi");
var someData = new SomeDataProvider {CustomerId = "156"};
user.Context.SharedData.Add(someData); //Make sure this is done only once.

CSharp Code

var request = user.CreateRequest("Please cancel my appointment.");
bot.Evaluate(request);
//Then in an expression get the data by providing its Type.

CSharp Code

[Expression("Cancel my appointment")]
public void CancelAppointment(Context context, Result result)
{
	var someData = context.SharedData.OfType<SomeDataProvider>();
	var customerId = someData.CustomerId;
	//Do something...
}

IranCahtBot
V.I.P
Posts: 27
Joined: Sat Feb 25, 2017 7:36 pm

Re: To pass Customer's Message and some parameters to a dial

Sat Jun 17, 2017 5:56 pm

Hello Dear FranzZ,

I sincerely appreciate the valuable information you have provided me and Thank you for your prompt response to my questions.

With regards
Ebrahimi

Return to “Feature Request and Suggestions”

Who is online

Users browsing this forum: No registered users and 1 guest