Ejemplo n.º 1
0
        /// <summary>
        /// Create a new voice message and send it to a recipient's phone number.
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the SendVoiceMessage service method.</param>
        ///
        /// <returns>The response from the SendVoiceMessage service method, as returned by PinpointSMSVoice.</returns>
        /// <exception cref="Amazon.PinpointSMSVoice.Model.BadRequestException">
        /// The input you provided is invalid.
        /// </exception>
        /// <exception cref="Amazon.PinpointSMSVoice.Model.InternalServiceErrorException">
        /// The API encountered an unexpected error and couldn't complete the request. You might
        /// be able to successfully issue the request again in the future.
        /// </exception>
        /// <exception cref="Amazon.PinpointSMSVoice.Model.TooManyRequestsException">
        /// You've issued too many requests to the resource. Wait a few minutes, and then try
        /// again.
        /// </exception>
        public virtual SendVoiceMessageResponse SendVoiceMessage(SendVoiceMessageRequest request)
        {
            var marshaller   = SendVoiceMessageRequestMarshaller.Instance;
            var unmarshaller = SendVoiceMessageResponseUnmarshaller.Instance;

            return(Invoke <SendVoiceMessageRequest, SendVoiceMessageResponse>(request, marshaller, unmarshaller));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initiates the asynchronous execution of the SendVoiceMessage operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the SendVoiceMessage operation on AmazonPinpointSMSVoiceClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndSendVoiceMessage
        ///         operation.</returns>
        public virtual IAsyncResult BeginSendVoiceMessage(SendVoiceMessageRequest request, AsyncCallback callback, object state)
        {
            var marshaller   = SendVoiceMessageRequestMarshaller.Instance;
            var unmarshaller = SendVoiceMessageResponseUnmarshaller.Instance;

            return(BeginInvoke <SendVoiceMessageRequest>(request, marshaller, unmarshaller,
                                                         callback, state));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initiates the asynchronous execution of the SendVoiceMessage operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the SendVoiceMessage operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public virtual Task <SendVoiceMessageResponse> SendVoiceMessageAsync(SendVoiceMessageRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = SendVoiceMessageRequestMarshaller.Instance;
            var unmarshaller = SendVoiceMessageResponseUnmarshaller.Instance;

            return(InvokeAsync <SendVoiceMessageRequest, SendVoiceMessageResponse>(request, marshaller,
                                                                                   unmarshaller, cancellationToken));
        }
        internal virtual SendVoiceMessageResponse SendVoiceMessage(SendVoiceMessageRequest request)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = SendVoiceMessageRequestMarshaller.Instance;
            options.ResponseUnmarshaller = SendVoiceMessageResponseUnmarshaller.Instance;

            return(Invoke <SendVoiceMessageResponse>(request, options));
        }
        /// <summary>
        /// Initiates the asynchronous execution of the SendVoiceMessage operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the SendVoiceMessage operation on AmazonPinpointSMSVoiceClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        ///
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndSendVoiceMessage
        ///         operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/pinpoint-sms-voice-2018-09-05/SendVoiceMessage">REST API Reference for SendVoiceMessage Operation</seealso>
        public virtual IAsyncResult BeginSendVoiceMessage(SendVoiceMessageRequest request, AsyncCallback callback, object state)
        {
            var options = new InvokeOptions();

            options.RequestMarshaller    = SendVoiceMessageRequestMarshaller.Instance;
            options.ResponseUnmarshaller = SendVoiceMessageResponseUnmarshaller.Instance;

            return(BeginInvoke(request, options, callback, state));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> SendVoiceMessage([FromBody] VoiceMessageModel model)
        {
            if (model == null || string.IsNullOrWhiteSpace(model.DestinationNumber) ||
                (string.IsNullOrWhiteSpace(model.SsmlMessage) && string.IsNullOrWhiteSpace(model.PlainTextMessage)))
            {
                return(BadRequestResult("Voice message"));
            }

            if (!ValidationHelper.IsValidPhoneNumber(model.DestinationNumber))
            {
                return(BadRequestResult("Voice message"));
            }

            using (AmazonPinpointSMSVoiceClient client = new AmazonPinpointSMSVoiceClient(_awsCredentials, RegionEndpoint.GetBySystemName(_awsSettings.Region)))
            {
                SendVoiceMessageRequest sendVoiceMessageRequest = new SendVoiceMessageRequest
                {
                    DestinationPhoneNumber = model.DestinationNumber,
                    OriginationPhoneNumber = _awsSettings.AwsTextVoiceMessage.OriginationNumber,
                    Content = new VoiceMessageContent
                    {
                        SSMLMessage = string.IsNullOrWhiteSpace(model.SsmlMessage) ? null : new SSMLMessageType
                        {
                            LanguageCode = model.LanguageCode ?? _awsSettings.LanguageCode, //en-US is ideal for US.
                            VoiceId      = model.VoiceId ?? "Matthew",
                            Text         = model.SsmlMessage
                        },
                        PlainTextMessage = !string.IsNullOrWhiteSpace(model.SsmlMessage) ? null : new PlainTextMessageType
                        {
                            LanguageCode = model.LanguageCode ?? _awsSettings.LanguageCode, //en-US is ideal for US.
                            VoiceId      = model.VoiceId ?? "Matthew",
                            Text         = model.PlainTextMessage
                        }
                    }
                };
                try
                {
                    SendVoiceMessageResponse response = await client.SendVoiceMessageAsync(sendVoiceMessageRequest);

                    if (response.HttpStatusCode != HttpStatusCode.OK)
                    {
                        return(BadRequestResult("Voice message"));
                    }
                }
                catch
                {
                    return(BadRequestResult("Voice message"));
                }
                return(new OkObjectResult(new { success = true, message = "Voice message sent." }));
            }
        }