Skip to main content

How to send an invitation via WhatsApp?

Using Rival’s External Distribution Webhook [Enabled by request]

Updated today

Overview

This guide shows you how to use Rival’s External Distribution Webhook to send WhatsApp messages (invitations or reminders) using Twilio and Zapier. You'll build a multi step Zap that listens for distribution events from Rival, sends WhatsApp messages using a Twilio template, and reports delivery back to Rival.

⚠️ While Zapier is a no-code automation tool, you will need to paste and lightly customize a provided JavaScript snippet to complete the Twilio WhatsApp message step.

Prerequisites

Before you begin, ensure you have:

  • A Zapier Pro account

  • A Twilio account with:

    • An approved WhatsApp Business number

    • Your number linked to a Meta Business Account

Set Up Your Research Domain in Rival

Create or Use a Rival Application

  1. In Rival, go to Settings → Applications.

  2. Create a new application or select an existing one.

  3. Inside the application, generate an API Key.

  4. Note:

    • Application ID

    • API Token

Import Participants with WhatsApp Numbers

  1. Go to Participants → Community → Imports.

  2. Click Actions → Import external community subscribers.

  3. Prepare a CSV with:

    • externalIdentifier (e.g., whatsapp-101)

    • A profile attribute like WhatsappNumber in E.164 format (+12345678900)

    • Any additional custom attributes you may want

  4. Upload the CSV. Refresh the page to view participants in the Directory.

The imported participants are created with their recontact method set to external. The external distribution webhook is triggered for all participants with 'External' recontact. If using multiple external platforms then you can sample your WhatsApp community using a 'WhatsApp' profile attribute.

Set Up Twilio for WhatsApp Messaging

WhatsApp Sender & Meta Approval

  1. In Twilio Console, go to Messaging → Senders → WhatsApp Senders.

  2. Submit a number for WhatsApp use. It must be linked to your Meta Business Account.

  3. Complete the WhatsApp Business approval process.

Messaging Service

  1. Navigate to Messaging → Services.

  2. Create a messaging service and assign your WhatsApp sender to it.

  3. Copy your Messaging Service SID.

Create WhatsApp Templates

  1. Go to Messaging → Content Template Builder in Twilio.

  2. Create message templates (e.g., "invitation", "reminder").

  3. Submit templates for Meta approval.

  4. Once approved, copy the Content SID for the template.

Collect These Details:

  • Account SID

  • Auth Token

  • Messaging Service SID

  • WhatsApp sender number

  • Content SID (template)

Build Your Zapier Workflow

Start by using our shared Zapier Template.

Step 1: Trigger – Rival Distribution Webhook

  • App: Rival (or Webhooks by Zapier if manually configured)

  • Event: External Distribution Message Published

  • Setup:

    • Use your x-application header (with environment prefix)

    • Enter your Rival API Token

    • Test to pull sample data

This trigger listens for messages with RecontactMethod: External, and provides:

  • chatUrl, distributionType, message

  • WhatsappNumber (as a profile attribute)

  • distributionId, participantId, messageId

Step 2: Fetch Twilio Credentials (Optional)

  • App: Storage by Zapier

  • Event: Get Value

  • Use this if you prefer to securely store your Twilio credentials as key-value pairs.

  • Otherwise, you can hardcode them directly in the code step.

Step 3: Send WhatsApp Message (Using JavaScript)

  • App: Code by Zapier

  • Event: Run JavaScript

Paste the following code into the Zap and edit these values:

  • accountSid → your Twilio Account SID

  • authToken → your Twilio Auth Token

  • fromWhatsAppNumber → your Twilio WhatsApp number (e.g., +12345678900)

  • templateSid → your approved Twilio Content Template SID

const {createHmac} = require('crypto') const {attributeLabels, attributeValues, chatUrl, distributionId, participantId, messageId, authToken} = inputData  const attributeMap = Object.fromEntries(   attributeLabels.split(',').map((label, index) =>      [label, attributeValues.split(',')[index]]   ) );  const toWhatsAppNumber = attributeMap['WhatsappNumber'] if (!toWhatsAppNumber) {     throw Error('No Whatsapp To Number') }  const accountSid = "ACfa62630ada60ea60565bc344ef20e1d5"; const fromWhatsAppNumber = "+12892127800"; const templateSid = 'HX826ca7f6aeada838cf439ab4e0b27b80'; const templateParams = {     // construct template params object for specified template     1: chatUrl };  const auth = Buffer.from(`${accountSid}:${authToken}`).toString('base64'); const baseURL = `https://api.twilio.com/2010-04-01/Accounts/${accountSid}/Messages.json`;  const formBody = Object.entries({         From: `whatsapp:${fromWhatsAppNumber}`,         To: `whatsapp:${toWhatsAppNumber}`,         ContentSid: templateSid,         ContentVariables: JSON.stringify(templateParams)     })     .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)     .join('&');  const response = await fetch(baseURL, {         method: 'POST',         headers: {             'Authorization': `Basic ${auth}`,             'Content-Type': 'application/x-www-form-urlencoded'         },         body: formBody     });  const messageResult = await response.json();  const lookupKey = messageResult.sid;  if (!lookupKey) {     throw new Error('No Sid in twilio response', messageResult); }  const unixTimestamp = Math.floor(Date.now() / 1000);  const registerPayload = {     lookupKey };  const signedElements = [];  signedElements.push(`t=${unixTimestamp}`); const stringToBeSigned = `${unixTimestamp}.${JSON.stringify(registerPayload)}`; const key = `${distributionId}:${participantId}`; const hmac = createHmac('sha256', key); const signature = hmac.update(stringToBeSigned).digest('hex'); signedElements.push(`s=${signature}`);  const registerUrl = `https://external-distribution.us1.dev-rivaltech.io/webhook/register/${messageId}`;  const registerResponse = await fetch(registerUrl, {     method: 'POST',     headers: {         'x-rival-signature': signedElements.join(','),         'Content-Type': 'application/json'     },     body: JSON.stringify(registerPayload) });  return registerResponse.json()

Limitations of WhatsApp Integration

Meta requires all messages to use pre-approved templates, so you can’t send free-form messages outside of active 24-hour sessions. You may face delays if template approvals are pending or limits are exceeded. WhatsApp messaging limits are tiered based on your brand’s reputation and sender quality. Only users who’ve opted in to WhatsApp can be contacted. Messages will fail if numbers are invalid or unregistered. Twilio applies per-message fees. And finally, to register delivery in Rival, your callback signature must be correctly generated and posted—if skipped, Rival will not track message delivery.

Test Your Integration

  1. Ensure you’ve imported a test participant with a valid WhatsApp number and RecontactMethod: External.

  2. Trigger a Rival distribution (invitation or reminder).

  3. Confirm message delivery via Twilio Logs and Zapier task history.

  4. Verify delivery registration appears in the Rival message dashboard.

Did this answer your question?