Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] How to send SMS programmatically using Amazon Amplify SDK for my Android app users?

Posted on November 11, 2022 By

Solution 1 :

Amazon lets you do this. Assuming you’re using Cognito for sign-up, you’ll want to use the post-confirmation Cognito lambda trigger.

  1. Set up your SNS account via the AWS Console, to send SMS messages. Send yourself a test message via the console.

  2. Run amplify auth update

  3. When it gets to the question Do you want to configure Lambda Triggers for Cognito?, answer Yes and choose the Post Confirmation trigger

  4. You need to grant SNS (SMS) permissions to the lambda. Update the PostConfirmation-cloudformation-template.json file to add a new statement under Resources.lambdaexecutionpolicy.Properties.PolicyDocument.Statement:

    {
    "Resources": {
        "lambdaexecutionpolicy": {
            "Properties": {
                "PolicyDocument": {
                    "Statement": [
                        {
                            "Effect": "Allow",
                            "Action": "sns:*",
                            "Resource": "*"
                        }
                    ]
                    ...
                }
            ...
            }
        ...
        }  
    ...
    }
    ...
    }
    
  5. Use this code for the trigger:

    var aws = require('aws-sdk');
    
    var sms = new aws.SNS();
    
    exports.handler = (event, context, callback) => {
      console.log(event);
    
      if (event.request.userAttributes.phone_number) {
        sendSMS(event.request.userAttributes.phone_number, "Congratulations " + event.userName + ", you have been confirmed: ", function (status) {
    
          // Return to Amazon Cognito
          callback(null, event);
        });
      } else {
        // Nothing to do, the user's phone number is unknown
        callback(null, event);
      }
    };
    
    function sendSMS(to, message, completedCallback) {
      const params = {
        Message: message, /* required */
        PhoneNumber: to
      };
      sns.publish(params, function (err, data) {
        if (err) {
          console.log(err, err.stack); // an error occurred
        } else {
          console.log(data);
        }
        completedCallback("SMS Sent");
      })
    };
    

Solution 2 :

Not sure if sending SMS is a service, Amazon Amplify provides.

But you could use a service like Twilio to send SMS (and much more) to phones.

Solution 3 :

AWS Amplify can help you setting up SMS, Email and Push notifications to your users by integrating with Amazon Pinpoint. Take a look at the documentation here: https://aws-amplify.github.io/docs/js/push-notifications.

Amazon Pinpoint allows you to create user segmentation, message templates, campaigns (with A/B testing and canary as well), Journeys (for email only so far), and so many more other things. You can integrate it and configure it using AWS Amplify, but some of those features I’ve mentioned are still not supported by AWS Amplify and you will have to either use the AWS Console to configure or use the AWS SDK to integrate with your app. You can leverage the AWS Amplify Auth module in order to get a valid Cognito token which will allow you to interact with Amazon Pinpoint directly.

READ  [FIXED] Amplify Android - The client issued a subsequent call to `Amplify.configure` after the first had already succeeded
Powered by Inline Related Posts

Problem :

I want to send a welcome message (SMS) to phone number of my app’s user when they will sign up using their phone number. I couldn’t find official documentation for this particular task.

Android Tags:aws-amplify, aws-amplify-sdk-android

Post navigation

Previous Post: [FIXED] Is it possible to switch from Start state to End state in android MotionLayout using Java/Kotlin?
Next Post: [FIXED] android – PHP / SQL: cannot save image at server but successful save image link at SQL database

Related Posts

[FIXED] android – How to match centering of RelativeLayout (centerInParent) and layer-list (gravity:center) as windowBackground? Android
[FIXED] android – Create a list from a string extracted from another list with Kotlin Android
[FIXED] Android Webview Sometimes Resets? Android
[FIXED] Iterate JSON array and use the Name value to identify a TextView Android Android
[FIXED] java – How does Garbage Collection identify orphaned objects? Android
[FIXED] stopwatch – How do I prevent auto click cheats in an android app? Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme