Send a text message and receive a response

0

Hi,

I am trying to send a text message to a phone using AWSSDK.Pinpoint using Visual Studio (VB.NET or C#).

I have written some code, but am not sure where to specify a mobile phone number yet.

Public Function Send(sendMessage As SendMessageInfo) As String Implements ISendMessage.Send
        Dim ppClient As New AmazonPinpointClient
        Dim ppSMSMessage As New SMSMessage With {
            .Body = sendMessage.Message,
            .MessageType = MessageType.PROMOTIONAL,
            .SenderId = "ACG",
            .Keyword = "ACG"
        }
        Dim ppMessageConfiguration As New DirectMessageConfiguration With {
            .SMSMessage = ppSMSMessage
        }
        Dim ppAddressConfiguration As New Dictionary(Of String, AddressConfiguration)
        Dim ppMessageRequest As MessageRequest
        Dim ppRequest As SendMessagesRequest
        Dim ppResponse As SendMessagesResponse
        Dim ppEndpoints = New Dictionary(Of String, EndpointSendConfiguration)

        ppAddressConfiguration.Add("1", New AddressConfiguration With {
            .ChannelType = ChannelType.SMS
        })

        ppMessageRequest = New MessageRequest With {
            .MessageConfiguration = ppMessageConfiguration,
            .Addresses = ppAddressConfiguration
        }

        ppRequest = New SendMessagesRequest With {
            .ApplicationId = "ACG",
            .MessageRequest = ppMessageRequest
        }

        ppResponse = ppClient.SendMessages(ppRequest)

        Return ppResponse.HttpStatusCode.ToString
    End Function

Note: I am already using S3 and SNS is working using AWSAccessKey and AWSSecretKey in the Web.config (eu-west-1)

I am currently getting "HttpErrorResponseException: The remote server returned an error: (404) Not Found." Previously, I was getting an error related to 'mobiletargeting' which I got around by adding an IAM group, and assigning it to the user.

Also, I was wondering if it possible to send the text message and receive a reply straight to e-mail?

Any help would be greatly appreciated.

Thanks,

asked 5 years ago334 views
1 Answer
0

I found that the following works for sending the text message.

Public Function Send(sendMessage As SendMessageInfo) As String Implements ISendMessage.Send
        Dim strReturn As String = String.Empty
        Dim strAppID As String = "abcdef123456" 'Pinpoint Project ID in the AWS console (not Project Name)
        Dim ppGetEndpointResponse As New GetEndpointResponse
        Dim ppEndpointResponse As EndpointResponse = ppGetEndpointResponse.EndpointResponse
        Dim ppDirectMessageConfiguration As New DirectMessageConfiguration With {
            .SMSMessage = New SMSMessage With {
                .Body = sendMessage.Message,
                .MessageType = MessageType.PROMOTIONAL
            }
        }
        Dim ppAddressConfiguration As New AddressConfiguration With {
            .ChannelType = ChannelType.SMS
        }
        Dim ppMessageRequest As New MessageRequest With {
            .MessageConfiguration = ppDirectMessageConfiguration,
            .Addresses = New Dictionary(Of String, AddressConfiguration) From {{sendMessage.PhoneNumber, ppAddressConfiguration}}
        }
        Dim ppSendMessagesRequest As New SendMessagesRequest With {
            .ApplicationId = strAppID,
            .MessageRequest = ppMessageRequest
        }

        Using ppClient As New AmazonPinpointClient
            strReturn = ppClient.SendMessages(ppSendMessagesRequest).HttpStatusCode.ToString
        End Using

        Return strReturn
    End Function
answered 5 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions