使用 pinpoint Nodejs 通过亚马逊免费电话号码发送短信

问题描述

大家好,我正在尝试通过 nodejs 使用免费电话号码通过 amazon pinpoint 发送 SMS 消息。请注意,为了安全起见,此代码中的数字已更改。这是我的代码

languageAwareSearchString() {...}

运行此代码后,我得到以下响应:

router.get("/send-text",async (req,res,next) => {
  try {
    const sender = "+18446850251";
    const destinationNumber = "+14325948991";
    const message = "HELLO from AWS";
    const applicationId = "myApplicationId";
    const messageType = "TRANSACTIONAL";
    AWS.config.update({ region: "us-east-1" });
    const pinpoint = new AWS.Pinpoint();
    const params = {
      ApplicationId: applicationId,MessageRequest: {
        Addresses: {
          [destinationNumber]: {
            BodyOverride: message,ChannelType: "SMS"
          }
        },MessageConfiguration: {
          SMSMessage: {
            Body: message,MessageType: messageType,OriginationNumber: sender
          }
        }
      }
    };
    const result = await pinpoint.sendMessages(params).promise();
    res.send(result);
  } catch (error) {
    console.log(error);
    next(error);
  }
});

旁注:我这样做的原因是我收到了一封来自 AWS 的电子邮件,我的理解是我不能再通过应用程序通过 SNS 主题向某人(一个 10 位长的代码)发送文本消息,并且必须从 6 月 1 日开始,使用 10DLC 长代码或免费电话通过精确定位发送它们是否正确?

image of settings

解决方法

如本 AWS 文档所述,您的假设是正确的:https://docs.aws.amazon.com/sns/latest/dg/channels-sms-awssupport-long-code.html

我刚刚使用这些值对此进行了测试:

    String message = "This is a Pinpoint test"; 
    String appId = "2fdc4442c6a2483f85eaf7a9430xxxxx";
    String originationNumber = "+14387956xxx" ;
    String destinationNumber = "+18195765xxx" ; 
    System.out.println("Sending a message" );

回复是:

+18195765xxx:MessageResult(DeliveryStatus=SUCCESSFUL,MessageId=4eniddp3gqrsarku8q2i2vnqqo0v8eov0t1dhs80,StatusCode=200,StatusMessage=MessageId:

可以从 AWS 管理控制台获取应用程序 ID:

enter image description here

要获取原始编号 - 您在 AWS 控制台中请求代码并在您的应用程序逻辑中使用该代码:

enter image description here

,

未明确启用 SNS 消息传递。请务必仔细检查此设置