Pigeon Agents Development Demo Pick List 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 Pick List 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.SDK.Sockets;
using Pigeon.Voice.Demo.Agents.Data.DB;
using Pigeon.Voice.Demo.Agents.Data.ORM;
#endregion //Using Directives
public class LutPickListAgent : PVLutAgentBase
{
#region Methods
public override void Process(PVLutResponse response)
{
try
{
PickList result = AgentsDBContext.Create().GetPickList(response.Request.OperatorId);
response.AddRecord(new List<string>()
{
0.ToString(),
string.Empty,
result.PickListNumber.ToString(),
Convert.ToInt32(result.Picked).ToString(),
});
}
catch (Exception ex)
{
response.Records.Clear();
response.AddRecord(new List<string>() { 1.ToString(), ex.Message });
throw ex;
}
}
#endregion //Methods
}
- Get input parameters: The LutPickListAgent 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 GetPickList method is called by passing in the operator ID from the request.
- If there is an error, such as no pick lists being available the GetPickList 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 GetPickList method executes successfully, it will return a PickList object containing all the database fields mapped to the PickList table in the database. An output record is added to the response containing the following fields:
- Result Code of 0 and an empty Result Message. This will indicate to the device a successful attempt at getting a pick list header.
- Pick List Number of the pick list record . The Voice Application on the device will use this pick list number on the next request to the LutPickItemsAgent to download the items for this pick list.
- Picked bit is returned to the device i.e. the boolean Picked field is converted to an integer (0 or 1) before adding it to the output record to the device.