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
- Register as a partner
- Register an agent
- Create a public/private key pair
- Update your agent's public key with Verified SMS
- Configure message hashing
- 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:
- 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
Configure message hashing on your development machine.
Run the following commands to set required environment variables:
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"
Navigate to the sample's root directory on your development machine.
Update the sample with the recipient phone number, your message content, and postback data.
C#
- Navigate to "/vsms-csharp-client-v1/".
- Open "StoreHashes.cs".
Update sms to the message content as a string.
For example, change
string sms = "Hello, sync world!";
tostring sms = "My first hashed message.";
.Update recipientAndMessages with an array of recipient phone number, message content, and postback data.
For example, change
List<RecipientAndMessage> recipientAndMessages = new List<RecipientAndMessage>() { new RecipientAndMessage("+16509999996", sms + "1", "+16509999996", agentId), new RecipientAndMessage("+16509999997", sms + "1", "+16509999997", agentId), new RecipientAndMessage("+16509999998", sms + "1", "+16509999998", agentId), new RecipientAndMessage("+16509999999", sms + "1", "+16509999999", agentId), };
to
List<RecipientAndMessage> recipientAndMessages = new List<RecipientAndMessage>() { new RecipientAndMessage("+16509999996", sms, "+16509999996", agentId), };
Save and close "StoreHashes.cs".
Java
- Navigate to "/src/main/java/com/google/communication/businessmessaging/verifiedsms/v1/examples/".
- Open "CreateHashesWithCapabilitiesRequestExampleAsync.java".
Update sms to the message content as a string.
For example, change
String sms = "Hello, sync world!";
toString sms = "My first hashed message.";
.Update recipientAndMessages with a mapping of the recipient phone number and the message content.
For example, change
List<RecipientAndMessage> recipientsAndMessages = new ArrayList<RecipientAndMessage>() { { add(new RecipientAndMessage("+16509999996", sms + "1", "+16509999996", agentId)); add(new RecipientAndMessage("+16509999997", sms + "1", "+16509999997", agentId)); add(new RecipientAndMessage("+16509999998", sms + "1", "+16509999998", agentId)); add(new RecipientAndMessage("+16509999999", sms + "1", "+16509999999", agentId)); } };
to
List<RecipientAndMessage> recipientsAndMessages = new ArrayList<RecipientAndMessage>() { { add(new RecipientAndMessage("+16509999996", sms, "+16509999996", agentId)); } };
Save and close "CreateHashesWithCapabilitiesRequestExampleAsync.java".
Node.js
- Open "store_hashes.js".
Update sms to the message content as a string.
For example, change
let sms = 'Hello, simple post world!';
tolet sms = 'My first hashed message.';
.Update recipientAndMessages with an array of the recipient phone number, message content, and postback data.
For example, change
let recipientAndMessages = [ { phoneNumber: '+16509999996', text: sms + '1', postbackData: '+16509999996', agentId: agentId }, { phoneNumber: '+16509999997', text: sms + '2', postbackData: '+16509999997', agentId: agentId }, { phoneNumber: '+16509999998', text: sms + '3', postbackData: '+16509999998', agentId: agentId }, { phoneNumber: '+16509999999', text: sms + '4', postbackData: '+16509999999', agentId: agentId } ];
to
let recipientAndMessages = [ { phoneNumber: '+16509999996', text: sms, postbackData: '+16509999996', agentId: agentId }, ];
Save and close "store_hashes.js".
PHP
- Open "store-hashes.php".
Update $sms to the message content as a string.
For example, change
$sms = 'Hello, simple post world!';
to$sms = 'Hello, simple post world!';
.Update $recipientAndMessages with an array of recipient phone number, message content, and postback data.
For example, change
$recipientAndMessages = array( array('phoneNumber' => '+16509999996', 'text' => $sms . '1', 'postbackData' => '+16509999996', 'agentId' => $agentId), array('phoneNumber' => '+16509999997', 'text' => $sms . '2', 'postbackData' => '+16509999997', 'agentId' => $agentId), array('phoneNumber' => '+16509999998', 'text' => $sms . '3', 'postbackData' => '+16509999998', 'agentId' => $agentId), array('phoneNumber' => '+16509999999', 'text' => $sms . '4', 'postbackData' => '+16509999999', 'agentId' => $agentId), );
to
$recipientAndMessages = array( array('phoneNumber' => '+16509999996', 'text' => $sms, 'postbackData' => '+16509999996', 'agentId' => $agentId), );
Save and close "store-hashes.php".
Python
- Open "create_hashes_example.py".
Update sms to the message content as a string.
For example, change
sms = 'Hello, simple post world!'
tosms = 'My first hashed message.'
.Update recipient_and_messages with an array of recipient phone number, message content, and postback data.
For example, change
recipient_and_messages = [ { 'phone_number': '+16509999996', 'text': sms + '1', 'postback_data': '+16509999996', 'agent_id': agent_id }, { 'phone_number': '+16509999997', 'text': sms + '2', 'postback_data': '+16509999997', 'agent_id': agent_id }, { 'phone_number': '+16509999998', 'text': sms + '3', 'postback_data': '+16509999998', 'agent_id': agent_id }, { 'phone_number': '+16509999999', 'text': sms + '4', 'postback_data': '+16509999999', 'agent_id': agent_id } ]
to
recipient_and_messages = [ { 'phone_number': '+16509999996', 'text': sms, 'postback_data': '+16509999996', 'agent_id': agent_id }, ]
Save and close "create_hashes_example.py".
In a terminal, navigate to the sample's root directory.
Run the hashing sample.
C#
dotnet build vsms-csharp-client-v1 /p:StartupObject=VerifiedSmsExample.StoreHashes
dotnet run --project vsms-csharp-client-v1
Java
Maven
mvn compile && mvn exec:java -Dexec.mainClass="com.google.communication.businessmessaging.verifiedsms.v1.examples.CreateHashesWithCapabilitiesRequestExampleAsync"
Gradle
gradle build && gradle -PmainClass=com.google.communication.businessmessaging.verifiedsms.v1.examples.CreateHashesWithCapabilitiesRequestExampleAsync runExample
Node.js
node store_hashes.js
PHP
php store-hashes.php
Python
python create_hashes_example.py
The sample script creates a hash of your message content specific to each recipient's phone number and stores those hashes with Verified SMS.
To only create hashes for phone numbers that are Verified SMS-enabled, use capability checks.
Send the SMS message
Now that the message hash is stored with Verified SMS, you're ready to send the SMS message.
- Send the text "Hello, world!" from your agent's sender ID to your test device as an SMS message.
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.