Pigeon Agents Development Web Agent - DatasmithSA/Pigeon-Voice-Training GitHub Wiki

A Web request is a synchronous message over HTTP; meaning that once a voice device makes a Web request to the Pigeon Voice Server, it will block (wait) for a response before the dialog continues to the next voice prompt/state in the Task/Voice Application running on the voice device.

Developing Pigeon Web Agents allows you to handle Web message requests from Vocollect Voice devices. A Web agent will need to be developed for every type of Web message request from the device e.g. one for a login request, another downloading a pick list etc.

In this example we will create a simple Web agent that writes out the default request details to the console, as well as the input parameters passed in from the Task/Voice Application. Lastly it will respond to the device with an an output record.

  1. Create a new class in the HTTP folder and call it: LutLocationAgent
  2. At the top of the file, add the following using clauses to import the Pigeon Voice SDK namespaces:
    • using Pigeon.Voice.SDK.AgentBase.HTTP;
    • using Pigeon.Voice.SDK.REST.Messages;
  3. Inherit from the PVWebAgentBase abstract class located in the Pigeon Voice SDK. This marks your agent class as being a Web Agent.
  4. Override the abstract Process method of the PVWebAgentBase class. It is within this method that your own business logic will be coded for the agent e.g. querying the WMS database or performing a calculation etc.
  5. The Process method provides a single input parameter, an PVWebResponse object which encapsulates both the response and request details. The PVWebResponse object contains a property called Request which holds a PVWebRequest object containing all the request details.
  6. In the example below we write the default request properties to the console for display purposes. These properties are common to all request Web requests from voice devices.
  7. The custom properties sent by the Task/Voice Application are held within the Request's InputRecordFieldValues property which is simply a generic list of strings. They can also be accessed directly via an a zero based index on the Request's indexer property e.g. response.Request[0] will return the input record's first field/column.
  8. Resonse records can be added with the AddRecord method on the PVWebResponse object. A record is simply a list of strings which will be returned to the device. Multiple records can be added to the response making up a table of records.
    #region Using Directives

    using System;
    using System.Collections.Generic;
    using Pigeon.Voice.SDK.AgentBase.HTTP;
    using Pigeon.Voice.SDK.REST.Messages;

    #endregion //Using Directives

    public class WebCountAgent : PVWebAgentBase
    {
        #region Methods

        public override void Process(PVWebResponse response)
        {
            //Inputs (do something with them)
            Console.WriteLine(response.Request.ClientIpAddress);
            Console.WriteLine(response.Request.CommandName);
            Console.WriteLine(response.Request.RequestDateTimeClientOriginalFormat);
            Console.WriteLine(response.Request.RequestDateTimeClient);
            Console.WriteLine(response.Request.RequestDateTimeServer);
            Console.WriteLine(response.Request.DeviceId);
            Console.WriteLine(response.Request.OperatorId);
            Console.WriteLine(response.Request.InputRecordFieldValuesCount);
            response.Request.InputRecordFieldValues.ForEach(fieldValue => Console.WriteLine(fieldValue));

            //Return a result code and result message.
            response.AddRecord(new List<string>() { "0", "Successfully updated quantity on server." });
        }

        #endregion //Methods
    }
⚠️ **GitHub.com Fallback** ⚠️