Pigeon Agents Development Demo Log Off Agent - DatasmithSA/Pigeon-Voice-Training GitHub Wiki
After creating a Pigeon Voice Agents library, follow the initial steps in creating a LUT agent, by adding a class, inheriting from the PVLutAgentBase class and overriding the base class' Process method.
N.B. keep in mind that a LUT message from the Voice Application on the device is synchronous i.e. the device blocks and waits for a response from the server before continuing with the dialog. Therefore every LUT agent is required to provide/add at least one output record to the response.
Add the following code to create the Log Off agent:
#region Using Directives
using System;
using System.Collections.Generic;
using Pigeon.Voice.SDK.AgentBase.TCP_IP;
using Pigeon.Voice.SDK.Sockets.LUT;
using Pigeon.Voice.Demo.Agents.Data.DB;
#endregion //Using Directives
public class LutLogOffAgent : PVLutAgentBase
{
#region Methods
public override void Process(PVLutResponse response)
{
try
{
AgentsDBContext.Create().LogOff(response.Request.OperatorId);
response.AddRecord(new List<string>() { 0.ToString(), string.Empty });
}
catch (Exception ex)
{
response.Records.Clear();
response.AddRecord(new List<string>() { 1.ToString(), ex.Message });
throw ex;
}
}
#endregion //Methods
}
- Get input parameters: The LutLogOffAgent does not have any input parameters since the only parameter required from the device is the Operator ID. The OperatorId property is provided in every request to an agent, hence the Voice Application does not explicitly send it as an input parameter. Instead the operator ID is retrieved from the Request.
-
Query database: an AgentsDBContext is created and the LogOff method is called by passing in the operator ID from the request.
- If there is an error, such as no the user with the given operator ID (user name) being available the LogOff method will throw an exception, the Process method will catch it and add an output record with a result code of 1 and the result message being the exception's message. The device will interpret any result code other than 0 as an error and speak the result message to the operator.
- If the LogOff method executes successfully, an output record is added to the response containing the following fields:
- If the LogOff method executes successfully, we then add an output record with a Result Code of 0 and an empty Result Message. This will indicate to the device a successful log off.