How to Schedule an SMS Using Vonage and Appwrite Messaging
最后更新 August 6, 2024

Appwrite, a popular open-source backend server (alternative to Firebase), received numerous requests from their community for a messaging feature. In response, they introduced Appwrite Messaging, a product that enables developers to send emails, SMS, and push notifications within their Appwrite projects. Some of you may have learned about this feature on Day 0 of their release week. Some of you may have learned about it from me when I prematurely tweeted about being a guest on their livestream. (Sorry, Eldad!)

Developers can now set up a full-functioning messaging service using Vonage as one of their providers. This includes scheduling SMS messages, particularly useful for sending timely reminders or updates. I'm going to show you how!

Vonage API Account

To complete this tutorial, you will need a Vonage API account. If you don’t have one already, you can sign up today and start building with free credit. Once you have an account, you can find your API Key and API Secret at the top of the Vonage API Dashboard.

Prerequisites

Setup Vonage

After you create a Vonage account, navigate to your Vonage API Dashboard.

Save Your API Key and Secret

On the main page of your dashboard, you should see your API key and secret. Save these numbers in a note so you can easily access them later. A section of the Vonage dashboard with API key and API Secret credentialsAPI Key and Secret

Buy a Vonage Phone Number

On the left-hand menu, find 'BUILD & MANAGE' > 'Numbers' > 'Buy Numbers'. Purchase a number that includes the SMS feature and Mobile type. If you are in the U.S., check out my blog, "What You Need to Know about 10DLC," to complete the requirements for a 10DLC number. Your application won't work without doing so. Save this phone number on the same note; we'll use it later.

The Buy Numbers page of the Vonage dashboard with a list of numbers available for purchaseBuy Number

Setup Appwrite

The cool thing about the messaging feature is that you will be executing it entirely on the Appwrite console.

Install Appwrite

If you haven't done so already, make sure you have Appwrite installed by running:

npm install appwrite

Once Appwrite is installed, go to your Appwrite Cloud console and create an organization. For this project, you can choose the Starter plan.

Create Project

Within your organization, go to the 'Projects' tab and click 'Create Project'.

The Buy Numbers page of the Vonage dashboard with a list of numbers available for purchaseBuy NumberGive your Project a name like "Schedule SMS" and hit 'Next'.

Create project window with "Name" and "Schedule SMS" as an example outlined.Name Your ProjectSelect the available region closest to you and click 'Create'. Currently, only Frankfurt is listed, and that's all right for now.

Create a project's step "Region" with "Frankfurt" selected.RegionNow that your project is created, under the 'Getting started' section, select 'Web' to add it as a platform.

The section to add a platform on the Appwrite console with Web outlineAdd PlatformComplete the hostname registration.

Hostname registration window with Name and Hostname as requiredHostname registrationOnce you finish that, go to your console and click on the project you just created.

Create User

Go to 'Auth' on the left-hand side and select 'Create user'. For testing purposes, I suggest you fill it out with your information.

When entering the phone number, it must start with a '+' and can have a maximum of fifteen digits.

Create user window with name, email, phone, password, and User ID with their values hidden.Create userNow, verify the user by clicking 'Verify account'. The status should then change to green and say verified {TYPE}.

Create Topic

Go back to 'Messaging' then to the 'Topics' tab and click 'Create topic'.

Under the Messaging section, the "Topics" tab is selected with "+ Create topic" outlined.Create TopicGive your topic a name like "Friends" and hit 'Create'.

Create topic window with "Friends" as an exampleName your topicAdd Subscriber

Now go to your topics and click on the topic you just created (In my case, 'Friends'). Click 'Add subscriber'.

Subscriber tab with "+ Add subscriber" outlinedAdd subscriber pageYou should see the user you created earlier. Click on their name to add them as subscribers. They'll be listed under your subscriber list—one for SMS and one for Email.

List of subscribers with their types (SMS, Email) outlinedList subscribers

Create Your Vonage Provider

Now go back to the main 'Messaging' view by clicking 'Messaging' on the left (again), and go to the 'Providers' tab. Create a provider with the SMS feature. Give your provider a name and select Vonage then hit 'Next'.

On the settings page, enter your Vonage API key and Vonage API secret. For the sender number, enter the phone number you purchased on the Vonage dashboard. The values of these fields should already be in the note you created at the beginning of this tutorial.

When entering the phone number, it must start with a '+' and can have a maximum of fifteen digits.

Create and Schedule Your Message

Now go back to the main 'Messaging' view by clicking 'Messaging' on the left (again). Make sure you're on the 'Messages' tab, click 'Create message', and choose the SMS option.

Messaging tab opened with "+ Create message" outlined.Messaging tabWrite the text for the message you want to send, then hit 'Next'.

Dashboard showing "Vonage does that!" as the message to be sent with a screenshot of the text from the phone's SMS app that shows the received message.Write a messageOn the Targets page, click 'Select topics' and choose the target you just created previously. You should see them listed under your 'Target'. Click 'Next'.

Select topics window with "Friends" checkedSelect friends topicHere on the Schedule page, you can decide when you want your message sent. You can either send it now or schedule a specific date and time down to the second.

"Schedule" shown as the last step to of "Create message" with the setting "Schedule", "Date", and "Time" outlined.Send SMSHit 'Send' and you should receive the message on the exact date and time you scheduled it. Woo!

Screenshot of text messaged received ("Vonage does that!") from the phone SMS application.Received SMS

Join the Party!

And just like that, you sent a scheduled SMS directly from the Appwrite Cloud Console using Vonage as a provider! As both a Vonage employee and Appwrite Hero, I was absolutely thrilled to show both communities how to use this feature. If you end up building a project with these products, I'd love to hear about it! You can tag me on X, formally known as Twitter. Feel free to follow my team and join our Vonage developer community Slack. Thanks for reading, and I'll catch you in the next one!

Diana PhamDeveloper Advocate

Diana is a developer advocate at Vonage. She likes eating fresh oysters.

Ready to start building?

Experience seamless connectivity, real-time messaging, and crystal-clear voice and video calls-all at your fingertips.

Subscribe to Our Developer Newsletter

Subscribe to our monthly newsletter to receive our latest updates on tutorials, releases, and events. No spam.