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,

gefragt vor 5 Jahren343 Aufrufe
1 Antwort
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
beantwortet vor 5 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen