Pigeon Agents Development Demo Confirm Pick Agent - DatasmithSA/Pigeon-Voice-Training GitHub Wiki
After creating a Pigeon Voice Agents library, follow the initial steps in creating a ODR agent, by adding a class, inheriting from the PVOdrAgentBase class and overriding the base class' Process method.
N.B. keep in mind that an ODR message from the Voice Application on the device is asynchronous i.e. the device does NOT block and wait for a response from the server before continuing with the dialog. Instead it adds the ODR message to a queue on the device and continues with the dialog. The device will then attempt to send the ODR message to the server in the background. If a network connection is not available it will continue trying to send the ODR until it receives an acknowledgement back from the Pigeon Voice Server. The acknowledgment is sent back by the Pigeon Voice Server automatically in the background and hence does not require any code to be written in the agent. Therefore an ODR agent such as the one in this example, does not require an output record to be added to the response.
Add the following code to create the Pick Items agent:
#region Using Directives
using System;
using Pigeon.Voice.SDK.Sockets.ODR;
using Pigeon.Voice.SDK.Sockets;
using Pigeon.Voice.SDK.AgentBase.TCP_IP;
using Pigeon.Voice.Demo.Agents.Data.DB;
#endregion //Using Directives
public class OdrConfirmPickAgent : PVOdrAgentBase
{
#region Methods
public override void Process(PVOdrResponse response)
{
try
{
GetInputParameters(response.Request, out int pickListNumber, out string sku, out int quantityPicked, out char pickStatusCode);
AgentsDBContext.Create().ConfirmPick(response.Request.OperatorId, pickListNumber, sku, quantityPicked, pickStatusCode);
}
catch (Exception ex)
{
throw ex;
}
}
private void GetInputParameters(
PVSocketRequest request,
out int pickListNumber, //0
out string sku, //1
out int quantityPicked, //2
out char pickedStatusCode) //3
{
if (!int.TryParse(request[0], out pickListNumber))
{
throw new Exception(string.Format("Pick list number {0} cannot be converted to an integer.", request[0]));
}
sku = request[1];
if (!int.TryParse(request[2], out quantityPicked))
{
throw new Exception(string.Format("Quantity picked {0} cannot be converted to an integer.", request[2]));
}
if (!char.TryParse(request[3], out pickedStatusCode))
{
throw new Exception(string.Format("Pick status code {0} cannot be converted to a character.", request[3]));
}
}
#endregion //Methods
}
- Get input parameters: The LutPickItemsAgent starts by simply reading the input parameters, which in this case they consist of the pick list number, SKU, quantity picked and the picked status code. This is done in the GetInputParameters method, by reading the input parameters from the Request i.e. a property of the PVLutResponse parameter on the agent's process method).
- Query database: an AgentsDBContext is created and the ConfirmPick method is called by passing in the pick list number from the request.
- If there is an error, such as the specific pick item not existing, the ConfirmPick method will throw an exception, the Process method will catch it and in this case will re-throw it. Hence in this specific example the catch statement is not in fact necessary, but rather provided as an example of where you could handle this exception if you prefer. In an ODR agent's case, the Pigeon Voice Server will not respond to the device with an acknowledgment if an exception is thrown within the agent. Swallowing the exception within the ODR agent will result in the Pigeon Voice Server responding with the acknowledgment to the device, which will indicate to the device that the operation was successful even though it wasn't since an exception was thrown. Therefore for this reason exceptions should always be re-thrown after/if handling them within the agents. This will allow the Pigeon Voice Server to handle it i.e. log it and send out an email notification.
- If the ConfirmPick method executes successfully, no other code is required to complete the pick confirmation operation i.e. no output record is required from an ODR agent.