Send a verified message

Sending a verified message is a two-step process: first, you store message hashes with Verified SMS, then you send the message content to the user through SMS. Once the user receives the message, the Messages app verifies that the message came from your agent.

Before you verify SMS messages you send to users, confirm that your message verification flow works with a device you manage.

Prerequisites

Before you can send a verified message, you need to

  1. Register as a partner
  2. Register an agent
  3. Create a public/private key pair
  4. Update your agent's public key with Verified SMS
  5. Configure message hashing
  6. Set up a test device

Additionally, you need the ability to send SMS messages from a sender ID associated with your agent.

Hash and store a message

With the Verified SMS Sample and SDK, you can get a user public key, hash a message, and store message hashes all at once.

Prerequisites

Before you store a hash, make sure that Verified SMS has your agent's current public key.

Additionally, gather some information:

  • Agent ID
  • Your API key or the path to your service account key on your development machine
  • Paths to the agent's private and public keys on your development machine
  • The phone number for the device you want to receive the message

Run the sample

  1. Configure message hashing on your development machine.

  2. Run the following commands to set required environment variables:

    export VERIFIED_SMS_AGENT_ID="AGENT_ID"
    export VERIFIED_SMS_PUBLIC_KEY_PATH="PATH_TO_PUBLIC_KEY.DER"
    export VERIFIED_SMS_PRIVATE_KEY_PATH="PATH_TO_PRIVATE_KEY_PKCS8.DER"
    export VERIFIED_SMS_SERVICE_ACCOUNT_PATH="PATH_TO_SERVICE_ACCOUNT_KEY.JSON"
    
  3. Navigate to the sample's root directory on your development machine.

  4. Update the sample with your message content and the recipient phone number.

    Java

    1. Navigate to "/src⁩/main⁩/java⁩/com⁩/google⁩/communication⁩/businessmessaging⁩/verifiedsms⁩/v1⁩/examples⁩/".
    2. Open "CreateHashesExampleAsync.java".
    3. Update sms to the message content as a string.

      For example, change 'String sms = "Hello, sync world!"; to String sms = "My first hashed message.";.

    4. Update recipient_and_messages with a mapping of the recipient phone number and the message content.

      For example, change

      Map<String, String> recipientsAndMessages = new HashMap<>();
      recipientsAndMessages.put("+16509999996", sms + "1");
      recipientsAndMessages.put("+16509999997", sms + "2");
      recipientsAndMessages.put("+16509999998", sms + "3");
      recipientsAndMessages.put("+16509999999", sms + "4");
      

      to

      Map<String, String> recipientsAndMessages = new HashMap<>();
      recipientsAndMessages.put("+16509999996", sms);
      
    5. Save and close "CreateHashesExampleAsync.java".

    Python

    1. Open "create_hashes_example.py".
    2. Update sms to the message content as a string.

      For example, change sms = 'Hello, simple post world!' to sms = 'My first hashed message.'.

    3. Update recipient_and_messages with a mapping of the recipient phone number and the message content.

      For example, change

      recipient_and_messages = {'+16509999996': sms + '1',
                                '+16509999997': sms + '2',
                                '+16509999998': sms + '3',
                                '+16509999999': sms + '4'}
      

      to

      recipient_and_messages = {'+16509999996': sms}
      
    4. Save and close "create_hashes_example.py".

    Node.js

    1. Open "store_hashes.js".
    2. Update sms to the message content as a string.

      For example, change let sms = 'Hello, simple post world!'; to let sms = 'My first hashed message.';.

    3. Update recipientAndMessages with a mapping of the recipient phone number and the message content.

      For example, change

      let recipientAndMessages = new Map([['+16509999996', sms + '1'],
        ['+16509999997', sms + '2'],
        ['+16509999998', sms + '3'],
        ['+16509999999', sms + '4']]);
      

      to

      let recipientAndMessages = new Map([['+16509999996', sms]]);
      
    4. Save and close "store_hashes.js".

  5. In a terminal, navigate to the sample's root directory.

  6. Run the hashing sample.

    Java (Maven)

    mvn compile && mvn exec:java -Dexec.mainClass="com.google.communication.businessmessaging.verifiedsms.v1.examples.CreateHashesExampleAsync"
    

    Java (Gradle)

    gradle build && gradle -PmainClass=com.google.communication.businessmessaging.verifiedsms.v1.examples.CreateHashesExampleAsync runExample
    

    Python

    python create_hashes_example.py
    

    Node.js

    node store_hashes.js
    

The sample script creates a hash of your message content specific to your recipient's phone number and stores that hash with Verified SMS.

Send the SMS message

Now that the message hash is stored with Verified SMS, you're ready to send the SMS message.

  1. Send the text "Hello, world!" from your agent's sender ID to your test device as an SMS message.
  2. On your test device, open the Messages app.

    You should receive "Hello, world!" as a new message on your device, and the conversation should display your agent's branding information. You may briefly see the message in a pending state while your device verifies the message.

Troubleshooting

If you have issues storing or verifying messages, confirm that you completed all the tasks in Prerequisites. If you continue having issues, contact us.

Next steps

When your device verifies the message from your agent, you're ready and able to send verified messages to your users.