aws-sdk#SNS TypeScript Examples

The following examples show how to use aws-sdk#SNS. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: sns.provider.ts    From loopback4-notifications with MIT License 6 votes vote down vote up
value() {
    return {
      publish: async (message: SNSMessage) => {
        if (message.receiver.to.length === 0) {
          throw new HttpErrors.BadRequest(
            'Message receiver not found in request',
          );
        }

        const publishes = message.receiver.to.map(receiver => {
          const msg: SNS.PublishInput = {
            Message: message.body,
            Subject: message.subject,
          };
          if (message.options?.smsType) {
            msg.MessageAttributes = {
              'AWS.SNS.SMS.SMSType': {
                DataType: 'String',
                StringValue: message.options.smsType,
              },
            };
          }
          if (receiver.type === SNSSubscriberType.PhoneNumber) {
            msg.PhoneNumber = receiver.id;
          } else if (receiver.type === SNSSubscriberType.Topic) {
            msg.TopicArn = receiver.id;
          } else {
            // Do nothing
          }

          return this.snsService.publish(msg).promise();
        });

        await Promise.all(publishes);
      },
    };
  }
Example #2
Source File: sns.provider.ts    From loopback4-notifications with MIT License 6 votes vote down vote up
constructor(
    @inject(SNSBindings.Config, {
      optional: true,
    })
    private readonly snsConfig?: SNS.ClientConfiguration,
  ) {
    if (this.snsConfig) {
      this.snsService = new SNS(this.snsConfig);
    } else {
      throw new HttpErrors.PreconditionFailed('AWS SNS Config missing !');
    }
  }
Example #3
Source File: mock-sns.provider.ts    From loopback4-microservice-catalog with MIT License 5 votes vote down vote up
constructor(
    @inject(SNSBindings.Config, {
      optional: true,
    })
    private readonly snsConfig?: SNS.ClientConfiguration,
  ) {}
Example #4
Source File: sns.provider.ts    From loopback4-notifications with MIT License 5 votes vote down vote up
snsService: SNS;
Example #5
Source File: index.ts    From opentuna with Apache License 2.0 5 votes vote down vote up
sns = new SNS()