Skip to content
Blog / Send WhatsApp messages with Vonage and Appwrite Functions
5 min

Send WhatsApp messages with Vonage and Appwrite Functions

Learn how to use an Appwrite Function Template to create a Whatsapp bot that will programmatically respond to incoming WhatsApp messages via Vonage.

Send WhatsApp messages with Vonage and Appwrite Functions

Function templates are pre-built Appwrite Functions that can be integrated into your Appwrite project with just a few clicks. Using them, you can easily incorporate new features and integrations into your app without writing additional code or managing infrastructure.

One such integration you can implement using Appwrite Functions is WhatsApp messaging via Vonage. In this blog, you will learn how you can use an Appwrite Function Template to create a Whatsapp bot that will programmatically respond to incoming WhatsApp messages via Vonage.

Setting up Vonage

The first step is to create a Vonage account. Head over to Vonage’s website and sign up to use Vonage Communication APIs. On the Vonage API Dashboard, visit the API Settings tab and copy the API Key, API Secret, and Signature Secret from there.

Vonage API Dashboard

After that, visit the Messages API Sandbox and enable WhatsApp to set up a test environment for our Appwrite Function template. Make sure to copy the Phone Number provided there (and join the WhatsApp channel with the instructions on the page. Once the Appwrite Function is deployed, we will return here to add the Function URL as the Inbound Webhook link.

Vonage Messages API Sandbox

Preparing the Appwrite Function

Now that we have all the necessary details from our Vonage account, let us get the function ready on Appwrite. Head over to your Appwrite project and visit the Functions page. From there, we will select the Templates tab, search for and select the WhatsApp with Vonage function template.

Functions Templates

This function requires 4 environment variables to setup:

  • VONAGE_API_KEY: API Key from our Vonage account (copied from the API Settings)
  • VONAGE_API_SECRET: API Secret from our Vonage account (copied from the API Settings)
  • VONAGE_API_SIGNATURE_SECRET: Secret used to sign and verify the JWT token sent by Vonage (copied from the API Settings)
  • VONAGE_WHATSAPP_NUMBER: Vonage WhatsApp number to send messages from (copied from the Messages API Sandbox)

After you have configured the environment variables, you must connect your Appwrite account with GitHub, select Create a new repository (this will generate a GitHub repository for you with the function), and leave the production branch and root settings as default to create this function.

Once the function is ready, visit the Domains tab on the function page and copy the domain to add to the Inbound Webhook link on the Messages API Sandbox page on your Vonage account.

Function Domain

Testing the Function

Once all the aforementioned steps are complete, it is time to test the function!

Open the WhatsApp app on your phone, join the Vonage WhatsApp Channel (via the steps mentioned on the Messaging API Sandbox on Vonage), and send any message to the WhatsApp number. You shall receive a message in the format: Hi there! You sent me: <SENT MESSAGE>

WhatsApp

Next steps

We’ve covered the basics, and now it’s your time to shine! With a few changes, you should be able to extend this template to fit your app. Be sure to check out the other available Function Templates. We’ve created many that could be of use in your projects. You can find the templates GitHub repository here.

For more information about Appwrite and Appwrite Functions:

Frequently asked questions

  • What is an Appwrite Function template?

    Function templates are prebuilt Appwrite Functions you can install in your project with a few clicks. They cover common integrations like WhatsApp via Vonage, Discord notifications, and Stripe webhooks, so you do not have to write the boilerplate yourself. See Appwrite Functions for the product overview.

  • Do I need a paid Vonage account to use this template?

    Not for testing. The Vonage Messages API Sandbox lets you send and receive WhatsApp messages on a test number for free. You only need a paid Vonage plan once you go to production with your own approved WhatsApp Business number.

  • How does the function receive incoming WhatsApp messages?

    Vonage forwards every inbound WhatsApp message to a webhook URL you configure. After deploying the function, you copy the domain from the Appwrite Function's Domains tab and paste it as the Inbound Webhook in Vonage's Messages API Sandbox. The function is then called every time a user sends a WhatsApp message.

  • How do I store WhatsApp environment variables securely?

    Configure the Vonage API key, secret, signature secret, and WhatsApp number as Appwrite Function environment variables. Appwrite encrypts them at rest and only injects them into the function runtime, so they never leak to the client. Never hardcode them in your function source.

  • Can I customize the auto reply behavior?

    Yes. The template is open source, so you can fork the generated GitHub repository and change the reply logic to call OpenAI, look up data in Appwrite Databases, or route messages to your support team. Push your changes and Appwrite redeploys automatically.

  • Can I use this approach for other messaging providers?

    Yes. The pattern of webhook in, function processes, response out works the same with Twilio, MessageBird, or any other SMS/WhatsApp provider. You only need to swap the SDK and webhook format. Appwrite also has Messaging for sending push, SMS, and email, which can complement an inbound function like this.

Start building with Appwrite today