/*******************************************************************************
* Copyright 2012-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use
* this file except in compliance with the License. A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file.
* This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
* *****************************************************************************
*
* AWS Tools for Windows (TM) PowerShell (TM)
*
*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text;
using Amazon.PowerShell.Common;
using Amazon.Runtime;
using Amazon.Connect;
using Amazon.Connect.Model;
namespace Amazon.PowerShell.Cmdlets.CONN
{
///
/// Initiates a flow to start a new chat for the customer. Response of this API provides
/// a token required to obtain credentials from the CreateParticipantConnection
/// API in the Amazon Connect Participant Service.
///
///
///
/// When a new chat contact is successfully created, clients must subscribe to the participant’s
/// connection for the created chat within 5 minutes. This is achieved by invoking CreateParticipantConnection
/// with WEBSOCKET and CONNECTION_CREDENTIALS.
///
/// A 429 error occurs in the following situations:
/// -
/// API rate limit is exceeded. API TPS throttling returns a
TooManyRequests
/// exception.
/// -
/// The quota
/// for concurrent active chats is exceeded. Active chat throttling returns a
LimitExceededException
.
///
/// If you use the ChatDurationInMinutes
parameter and receive a 400 error,
/// your account may not support the ability to configure custom chat durations. For more
/// information, contact Amazon Web Services Support.
///
/// For more information about chat, see Chat
/// in the Amazon Connect Administrator Guide.
///
///
[Cmdlet("Start", "CONNChatContact", SupportsShouldProcess = true, ConfirmImpact = ConfirmImpact.Medium)]
[OutputType("Amazon.Connect.Model.StartChatContactResponse")]
[AWSCmdlet("Calls the Amazon Connect Service StartChatContact API operation.", Operation = new[] {"StartChatContact"}, SelectReturnType = typeof(Amazon.Connect.Model.StartChatContactResponse))]
[AWSCmdletOutput("Amazon.Connect.Model.StartChatContactResponse",
"This cmdlet returns an Amazon.Connect.Model.StartChatContactResponse object containing multiple properties. The object can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack."
)]
public partial class StartCONNChatContactCmdlet : AmazonConnectClientCmdlet, IExecutor
{
#region Parameter Attribute
///
///
/// A custom key-value pair using an attribute map. The attributes are standard Amazon
/// Connect attributes. They can be accessed in flows just like any other contact attributes.
/// There can be up to 32,768 UTF-8 bytes across all key-value pairs per contact. Attribute
/// keys can include only alphanumeric, dash, and underscore characters.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("Attributes")]
public System.Collections.Hashtable Attribute { get; set; }
#endregion
#region Parameter ChatDurationInMinute
///
///
/// The total duration of the newly started chat session. If not specified, the chat session
/// duration defaults to 25 hour. The minimum configurable time is 60 minutes. The maximum
/// configurable time is 10,080 minutes (7 days).
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("ChatDurationInMinutes")]
public System.Int32? ChatDurationInMinute { get; set; }
#endregion
#region Parameter ContactFlowId
///
///
/// The identifier of the flow for initiating the chat. To see the ContactFlowId in the
/// Amazon Connect console user interface, on the navigation menu go to Routing,
/// Contact Flows. Choose the flow. On the flow page, under the name of the flow,
/// choose Show additional flow information. The ContactFlowId is the last part
/// of the ARN, shown here in bold: arn:aws:connect:us-west-2:xxxxxxxxxxxx:instance/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/contact-flow/846ec553-a005-41c0-8341-xxxxxxxxxxxx
///
///
#if !MODULAR
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true)]
#else
[System.Management.Automation.Parameter(Position = 0, ValueFromPipelineByPropertyName = true, ValueFromPipeline = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String ContactFlowId { get; set; }
#endregion
#region Parameter InitialMessage_Content
///
///
/// The content of the chat message. - For
text/plain
and text/markdown
, the Length Constraints
/// are Minimum of 1, Maximum of 1024. - For
application/json
, the Length Constraints are Minimum of 1, Maximum
/// of 12000. - For
application/vnd.amazonaws.connect.message.interactive.response
, the
/// Length Constraints are Minimum of 1, Maximum of 12288.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String InitialMessage_Content { get; set; }
#endregion
#region Parameter InitialMessage_ContentType
///
///
/// The type of the content. Supported types are text/plain
, text/markdown
,
/// application/json
, and application/vnd.amazonaws.connect.message.interactive.response
.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String InitialMessage_ContentType { get; set; }
#endregion
#region Parameter ParticipantDetails_DisplayName
///
///
/// Display name of the participant.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String ParticipantDetails_DisplayName { get; set; }
#endregion
#region Parameter InstanceId
///
///
/// The identifier of the Amazon Connect instance. You can find
/// the instance ID in the Amazon Resource Name (ARN) of the instance.
///
///
#if !MODULAR
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
#else
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true, Mandatory = true)]
[System.Management.Automation.AllowEmptyString]
[System.Management.Automation.AllowNull]
#endif
[Amazon.PowerShell.Common.AWSRequiredParameter]
public System.String InstanceId { get; set; }
#endregion
#region Parameter PersistentChat_RehydrationType
///
///
/// The contactId that is used for rehydration depends on the rehydration type. RehydrationType
/// is required for persistent chat. ENTIRE_PAST_SESSION
: Rehydrates a chat from the most recently terminated
/// past chat contact of the specified past ended chat session. To use this type, provide
/// the initialContactId
of the past ended chat session in the sourceContactId
/// field. In this type, Amazon Connect determines the most recent chat contact on the
/// specified chat session that has ended, and uses it to start a persistent chat. FROM_SEGMENT
: Rehydrates a chat from the past chat contact that is specified
/// in the sourceContactId
field.
The actual contactId used for rehydration is provided in the response of this API.
///
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[AWSConstantClassSource("Amazon.Connect.RehydrationType")]
public Amazon.Connect.RehydrationType PersistentChat_RehydrationType { get; set; }
#endregion
#region Parameter RelatedContactId
///
///
/// The unique identifier for an Amazon Connect contact. This identifier is related to
/// the chat starting.You cannot provide data for both RelatedContactId and PersistentChat.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String RelatedContactId { get; set; }
#endregion
#region Parameter PersistentChat_SourceContactId
///
///
/// The contactId from which a persistent chat session must be started.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String PersistentChat_SourceContactId { get; set; }
#endregion
#region Parameter SupportedMessagingContentType
///
///
/// The supported chat message content types. Supported types are text/plain
,
/// text/markdown
, application/json
, application/vnd.amazonaws.connect.message.interactive
,
/// and application/vnd.amazonaws.connect.message.interactive.response
. Content types must always contain text/plain
. You can then put any other
/// supported type in the list. For example, all the following lists are valid because
/// they contain text/plain
: [text/plain, text/markdown, application/json]
,
/// [text/markdown, text/plain]
, [text/plain, application/json, application/vnd.amazonaws.connect.message.interactive.response]
.
/// The type application/vnd.amazonaws.connect.message.interactive
is required
/// to use the Show
/// view flow block.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
[Alias("SupportedMessagingContentTypes")]
public System.String[] SupportedMessagingContentType { get; set; }
#endregion
#region Parameter ClientToken
///
///
/// A unique, case-sensitive identifier that you provide to ensure the idempotency of
/// the request. If not provided, the Amazon Web Services SDK populates this field. For
/// more information about idempotency, see Making
/// retries safe with idempotent APIs.
///
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public System.String ClientToken { get; set; }
#endregion
#region Parameter Select
///
/// Use the -Select parameter to control the cmdlet output. The default value is '*'.
/// Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.Connect.Model.StartChatContactResponse).
/// Specifying the name of a property of type Amazon.Connect.Model.StartChatContactResponse will result in that property being returned.
/// Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public string Select { get; set; } = "*";
#endregion
#region Parameter PassThru
///
/// Changes the cmdlet behavior to return the value passed to the ContactFlowId parameter.
/// The -PassThru parameter is deprecated, use -Select '^ContactFlowId' instead. This parameter will be removed in a future version.
///
[System.Obsolete("The -PassThru parameter is deprecated, use -Select '^ContactFlowId' instead. This parameter will be removed in a future version.")]
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter PassThru { get; set; }
#endregion
#region Parameter Force
///
/// This parameter overrides confirmation prompts to force
/// the cmdlet to continue its operation. This parameter should always
/// be used with caution.
///
[System.Management.Automation.Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }
#endregion
protected override void ProcessRecord()
{
this._AWSSignerType = "v4";
base.ProcessRecord();
var resourceIdentifiersText = FormatParameterValuesForConfirmationMsg(nameof(this.ContactFlowId), MyInvocation.BoundParameters);
if (!ConfirmShouldProceed(this.Force.IsPresent, resourceIdentifiersText, "Start-CONNChatContact (StartChatContact)"))
{
return;
}
var context = new CmdletContext();
// allow for manipulation of parameters prior to loading into context
PreExecutionContextLoad(context);
#pragma warning disable CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (ParameterWasBound(nameof(this.Select)))
{
context.Select = CreateSelectDelegate(Select) ??
throw new System.ArgumentException("Invalid value for -Select parameter.", nameof(this.Select));
if (this.PassThru.IsPresent)
{
throw new System.ArgumentException("-PassThru cannot be used when -Select is specified.", nameof(this.Select));
}
}
else if (this.PassThru.IsPresent)
{
context.Select = (response, cmdlet) => this.ContactFlowId;
}
#pragma warning restore CS0618, CS0612 //A class member was marked with the Obsolete attribute
if (this.Attribute != null)
{
context.Attribute = new Dictionary(StringComparer.Ordinal);
foreach (var hashKey in this.Attribute.Keys)
{
context.Attribute.Add((String)hashKey, (String)(this.Attribute[hashKey]));
}
}
context.ChatDurationInMinute = this.ChatDurationInMinute;
context.ClientToken = this.ClientToken;
context.ContactFlowId = this.ContactFlowId;
#if MODULAR
if (this.ContactFlowId == null && ParameterWasBound(nameof(this.ContactFlowId)))
{
WriteWarning("You are passing $null as a value for parameter ContactFlowId which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.InitialMessage_Content = this.InitialMessage_Content;
context.InitialMessage_ContentType = this.InitialMessage_ContentType;
context.InstanceId = this.InstanceId;
#if MODULAR
if (this.InstanceId == null && ParameterWasBound(nameof(this.InstanceId)))
{
WriteWarning("You are passing $null as a value for parameter InstanceId which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.ParticipantDetails_DisplayName = this.ParticipantDetails_DisplayName;
#if MODULAR
if (this.ParticipantDetails_DisplayName == null && ParameterWasBound(nameof(this.ParticipantDetails_DisplayName)))
{
WriteWarning("You are passing $null as a value for parameter ParticipantDetails_DisplayName which is marked as required. In case you believe this parameter was incorrectly marked as required, report this by opening an issue at https://github.com/aws/aws-tools-for-powershell/issues.");
}
#endif
context.PersistentChat_RehydrationType = this.PersistentChat_RehydrationType;
context.PersistentChat_SourceContactId = this.PersistentChat_SourceContactId;
context.RelatedContactId = this.RelatedContactId;
if (this.SupportedMessagingContentType != null)
{
context.SupportedMessagingContentType = new List(this.SupportedMessagingContentType);
}
// allow further manipulation of loaded context prior to processing
PostExecutionContextLoad(context);
var output = Execute(context) as CmdletOutput;
ProcessOutput(output);
}
#region IExecutor Members
public object Execute(ExecutorContext context)
{
var cmdletContext = context as CmdletContext;
// create request
var request = new Amazon.Connect.Model.StartChatContactRequest();
if (cmdletContext.Attribute != null)
{
request.Attributes = cmdletContext.Attribute;
}
if (cmdletContext.ChatDurationInMinute != null)
{
request.ChatDurationInMinutes = cmdletContext.ChatDurationInMinute.Value;
}
if (cmdletContext.ClientToken != null)
{
request.ClientToken = cmdletContext.ClientToken;
}
if (cmdletContext.ContactFlowId != null)
{
request.ContactFlowId = cmdletContext.ContactFlowId;
}
// populate InitialMessage
var requestInitialMessageIsNull = true;
request.InitialMessage = new Amazon.Connect.Model.ChatMessage();
System.String requestInitialMessage_initialMessage_Content = null;
if (cmdletContext.InitialMessage_Content != null)
{
requestInitialMessage_initialMessage_Content = cmdletContext.InitialMessage_Content;
}
if (requestInitialMessage_initialMessage_Content != null)
{
request.InitialMessage.Content = requestInitialMessage_initialMessage_Content;
requestInitialMessageIsNull = false;
}
System.String requestInitialMessage_initialMessage_ContentType = null;
if (cmdletContext.InitialMessage_ContentType != null)
{
requestInitialMessage_initialMessage_ContentType = cmdletContext.InitialMessage_ContentType;
}
if (requestInitialMessage_initialMessage_ContentType != null)
{
request.InitialMessage.ContentType = requestInitialMessage_initialMessage_ContentType;
requestInitialMessageIsNull = false;
}
// determine if request.InitialMessage should be set to null
if (requestInitialMessageIsNull)
{
request.InitialMessage = null;
}
if (cmdletContext.InstanceId != null)
{
request.InstanceId = cmdletContext.InstanceId;
}
// populate ParticipantDetails
var requestParticipantDetailsIsNull = true;
request.ParticipantDetails = new Amazon.Connect.Model.ParticipantDetails();
System.String requestParticipantDetails_participantDetails_DisplayName = null;
if (cmdletContext.ParticipantDetails_DisplayName != null)
{
requestParticipantDetails_participantDetails_DisplayName = cmdletContext.ParticipantDetails_DisplayName;
}
if (requestParticipantDetails_participantDetails_DisplayName != null)
{
request.ParticipantDetails.DisplayName = requestParticipantDetails_participantDetails_DisplayName;
requestParticipantDetailsIsNull = false;
}
// determine if request.ParticipantDetails should be set to null
if (requestParticipantDetailsIsNull)
{
request.ParticipantDetails = null;
}
// populate PersistentChat
var requestPersistentChatIsNull = true;
request.PersistentChat = new Amazon.Connect.Model.PersistentChat();
Amazon.Connect.RehydrationType requestPersistentChat_persistentChat_RehydrationType = null;
if (cmdletContext.PersistentChat_RehydrationType != null)
{
requestPersistentChat_persistentChat_RehydrationType = cmdletContext.PersistentChat_RehydrationType;
}
if (requestPersistentChat_persistentChat_RehydrationType != null)
{
request.PersistentChat.RehydrationType = requestPersistentChat_persistentChat_RehydrationType;
requestPersistentChatIsNull = false;
}
System.String requestPersistentChat_persistentChat_SourceContactId = null;
if (cmdletContext.PersistentChat_SourceContactId != null)
{
requestPersistentChat_persistentChat_SourceContactId = cmdletContext.PersistentChat_SourceContactId;
}
if (requestPersistentChat_persistentChat_SourceContactId != null)
{
request.PersistentChat.SourceContactId = requestPersistentChat_persistentChat_SourceContactId;
requestPersistentChatIsNull = false;
}
// determine if request.PersistentChat should be set to null
if (requestPersistentChatIsNull)
{
request.PersistentChat = null;
}
if (cmdletContext.RelatedContactId != null)
{
request.RelatedContactId = cmdletContext.RelatedContactId;
}
if (cmdletContext.SupportedMessagingContentType != null)
{
request.SupportedMessagingContentTypes = cmdletContext.SupportedMessagingContentType;
}
CmdletOutput output;
// issue call
var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);
try
{
var response = CallAWSServiceOperation(client, request);
object pipelineOutput = null;
pipelineOutput = cmdletContext.Select(response, this);
output = new CmdletOutput
{
PipelineOutput = pipelineOutput,
ServiceResponse = response
};
}
catch (Exception e)
{
output = new CmdletOutput { ErrorResponse = e };
}
return output;
}
public ExecutorContext CreateContext()
{
return new CmdletContext();
}
#endregion
#region AWS Service Operation Call
private Amazon.Connect.Model.StartChatContactResponse CallAWSServiceOperation(IAmazonConnect client, Amazon.Connect.Model.StartChatContactRequest request)
{
Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Connect Service", "StartChatContact");
try
{
#if DESKTOP
return client.StartChatContact(request);
#elif CORECLR
return client.StartChatContactAsync(request).GetAwaiter().GetResult();
#else
#error "Unknown build edition"
#endif
}
catch (AmazonServiceException exc)
{
var webException = exc.InnerException as System.Net.WebException;
if (webException != null)
{
throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
}
throw;
}
}
#endregion
internal partial class CmdletContext : ExecutorContext
{
public Dictionary Attribute { get; set; }
public System.Int32? ChatDurationInMinute { get; set; }
public System.String ClientToken { get; set; }
public System.String ContactFlowId { get; set; }
public System.String InitialMessage_Content { get; set; }
public System.String InitialMessage_ContentType { get; set; }
public System.String InstanceId { get; set; }
public System.String ParticipantDetails_DisplayName { get; set; }
public Amazon.Connect.RehydrationType PersistentChat_RehydrationType { get; set; }
public System.String PersistentChat_SourceContactId { get; set; }
public System.String RelatedContactId { get; set; }
public List SupportedMessagingContentType { get; set; }
public System.Func Select { get; set; } =
(response, cmdlet) => response;
}
}
}