Pigeon Agents Development Demo Pick Items 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 Items 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.ORM;
    using Pigeon.Voice.SDK.Sockets;
    using Pigeon.Voice.Demo.Agents.Data.DB;

    #endregion //Using Directives

    public class LutPickItemsAgent : PVLutAgentBase
    {
        #region Methods

        public override void Process(PVLutResponse response)
        {
            try
            {
                GetInputParameters(response.Request, out int pickListNumber);
                List<PickItem> result = AgentsDBContext.Create().GetPickListItems(pickListNumber);
                result.ForEach(p => response.AddRecord(new List<string>()
                {
                    0.ToString(),
                    string.Empty,
                    p.Sku,
                    p.Location,
                    p.CheckDigits,
                    p.QuantityToPick.ToString(),
                    p.QuantityToPick.ToString(), //Quantity remaining. Field used only on the device.
                    p.Description,
                    p.QuantityPicked.HasValue ? p.QuantityPicked.Value.ToString() : 0.ToString(), //Field used only on the device.
                    p.PickStatusCode.HasValue ? p.PickStatusCode.ToString() : string.Empty //Field used only on the device.
                }));
            }
            catch (Exception ex)
            {
                response.Records.Clear();
                response.AddRecord(new List<string>() { 1.ToString(), ex.Message });
                throw ex;
            }
        }

        private void GetInputParameters(PVSocketRequest request, out int pickListNumber)
        {
            if (request.InputRecordFieldValues.Count != 1)
            {
                throw new Exception(string.Format("Invalid number of inputs supplied to {0}.", request.CommandName));
            }
            if (!int.TryParse(request[0], out pickListNumber))
            {
                throw new Exception(string.Format("Pick list number {0} cannot be converted to an integer.", request[0]));
            }
        }

        #endregion //Methods
    }
  1. Get input parameters: The LutPickItemsAgent starts by simply reading the input parameters, which in this case is only the pick list number. 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).
  2. Query database: an AgentsDBContext is created and the GetPickListItems method is called by passing in the pick list number from the request.
    • If there is an error, such as no pick items being available the GetPickListItems 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 GetPickListItems method executes successfully, it will return a generic list of PickItem objects which are linked to the pick list. Each PickItem object contains all the database fields mapped to the PickItem table in the database. For each PickItem object in the list, an output record will be added to the response with the following fields:
      • Result Code of 0 and an empty Result Message. This will indicate to the device a successful attempt at getting a list of pick items
      • Sku of the item to be picked.
      • Location of where the item the item to be picked is located in the warehouse.
      • Check Digits of at the location of the item.
      • Quantity To Pick of the item the given location.
      • Quantity Remaining will be set to the same value as the Quantity To Pick. This field is only used on the device to count down the quantity remaining to be picked on each item.
      • Description of the item to be picked.
      • Quantity Picked will be set to either 0 or the existing value if there is a value specified in the database. This field is only used on the device to update the quantity picked, which will be sent back to the server in the call to the OdrConfirmPickAgent agent.
      • Pick Status Code will be set to empty, as this field will also only be used by the device to update the status of a pick confirmation i.e. 'R' for a complete pick and 'S' for a short pick. This field will be sent back to the server in the call to the OdrConfirmPickAgent agent.
⚠️ **GitHub.com Fallback** ⚠️