/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under the license found in the
* LICENSE file in the root directory of this source tree.
*/
using System;
using System.Collections.Generic;
using Meta.Voice;
namespace Meta.WitAi.Requests
{
public class VoiceServiceRequestOptions : INLPAudioRequestOptions, INLPTextRequestOptions
{
///
/// Unique request id used for request tracking internally & externally
///
public string RequestId { get; private set; }
///
/// Additional request query parameters to be sent with the request
///
public Dictionary QueryParams { get; private set; }
public class QueryParam
{
public string key;
public string value;
}
///
/// The text to be submitted for a text request
///
public string Text { get; set; }
///
/// The threshold to be used for an audio request
///
public float AudioThreshold { get; set; }
///
/// Setup with a randomly generated guid
///
public VoiceServiceRequestOptions(params QueryParam[] newParams)
{
RequestId = GetUniqueRequestId();
QueryParams = ConvertQueryParams(newParams);
}
///
/// Setup with a specific guid
///
public VoiceServiceRequestOptions(string newRequestId, params QueryParam[] newParams)
{
RequestId = string.IsNullOrEmpty(newRequestId) ? GetUniqueRequestId() : newRequestId;
QueryParams = ConvertQueryParams(newParams);
}
///
/// Generates a random guid
///
protected virtual string GetUniqueRequestId() => Guid.NewGuid().ToString();
///
/// Generates a dictionary of key/value strings from a query param array
///
public static Dictionary ConvertQueryParams(QueryParam[] newParams)
{
Dictionary results = new Dictionary();
foreach (var param in newParams)
{
if (!string.IsNullOrEmpty(param.key))
{
results[param.key] = results[param.value];
}
}
return results;
}
}
}