Connect with Vaarto
If you build a product that sends WhatsApp messages for your customers, Connect with Vaarto replaces “go to Vaarto, create an API key, paste it here, now add a webhook…” with one button.
Your customer clicks it, signs in to Vaarto in a popup, picks their workspace and approves. Your server then receives an API key for that workspace and, if you asked for events, a webhook already pointed at your server with its signing secret.
How it works
Section titled “How it works”- Your page calls
VaartoConnect.open(). A Vaarto popup opens. - The customer signs in (if they aren’t already), picks a workspace, and sees exactly what your app will get: the API permissions and where events will be sent.
- They click Connect. The popup hands a one-time code back to your page and closes.
- Your page sends the code to your server.
- Your server exchanges the code, with your client secret, for the API key and webhook secret. The code works once and expires after 5 minutes.
The API key never passes through a browser: only your server, holding the client secret, can turn a code into credentials.
1. Get registered
Section titled “1. Get registered”Connect is available to approved partners. Contact us with:
| We need | Example | Why |
|---|---|---|
| Product name and logo | Talking Tech | Shown on the consent screen |
| Website | https://talkingtech.ai |
Shown on the consent screen |
| Allowed origins | https://app.talkingtech.ai, https://*.talkingtech.ai, http://localhost:3000 |
Only pages on these origins can open the popup and receive the code |
| Webhook domains | talkingtech.ai |
Each customer’s webhook URL must be on one of these (subdomains included) |
| Permissions | Send messages, Read messages | The scopes the customer’s API key gets |
| Events | message.received, message.status |
What the webhook receives. Skip if you don’t need a webhook |
You receive a client ID (vci_…, public) and a client secret (vcs_…, shown once,
keep it on your server only). If the secret leaks, ask us to rotate it; existing connections
keep working.
2. Add the button to your page
Section titled “2. Add the button to your page”Everything runs on one script, served by Vaarto, so you always have the latest version with nothing to install or upgrade:
<script src="https://app.vaarto.com/connect.js"></script>It adds window.VaartoConnect.open(options). Pick your stack below.
<script src="https://app.vaarto.com/connect.js"></script>
<button id="connect-vaarto">Connect WhatsApp with Vaarto</button>
<script> document.getElementById("connect-vaarto").addEventListener("click", async () => { try { const { code } = await VaartoConnect.open({ clientId: "vci_your_client_id", webhookUrl: "https://hooks.talkingtech.ai/vaarto/customer-123", }); await fetch("/integrations/vaarto/complete", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ code }), }); } catch (error) { console.warn("Vaarto connect did not finish:", error.code); // cancelled | closed | popup_blocked } });</script>Works the same in WordPress, PHP, Rails, Django or any server-rendered page.
Add this file once. It loads the script a single time, however many buttons use it.
type ConnectOptions = { clientId: string; webhookUrl?: string; state?: string };type ConnectResult = { code: string; state: string };
declare global { interface Window { VaartoConnect?: { open(options: ConnectOptions): Promise<ConnectResult> }; }}
let loading: Promise<void> | undefined;
/** Loads https://app.vaarto.com/connect.js once. */export function loadVaartoConnect(): Promise<void> { if (window.VaartoConnect) return Promise.resolve(); loading ??= new Promise((resolve, reject) => { const script = document.createElement("script"); script.src = "https://app.vaarto.com/connect.js"; script.async = true; script.onload = () => resolve(); script.onerror = () => { loading = undefined; reject(new Error("Could not load Vaarto Connect")); }; document.head.append(script); }); return loading;}import { useCallback, useEffect, useState } from "react";import { loadVaartoConnect } from "./vaarto-connect";
export function useVaartoConnect(options: { clientId: string; webhookUrl?: string }) { const [ready, setReady] = useState(false); const [pending, setPending] = useState(false);
// Loaded on mount, so the click can open the popup straight away. useEffect(() => { loadVaartoConnect().then(() => setReady(true), console.error); }, []);
const connect = useCallback(async () => { if (!window.VaartoConnect) return null; setPending(true); try { return await window.VaartoConnect.open(options); } catch (error) { const code = (error as { code?: string }).code; if (code === "cancelled" || code === "closed") return null; throw error; } finally { setPending(false); } }, [options.clientId, options.webhookUrl]);
return { connect, ready, pending };}import { useVaartoConnect } from "./use-vaarto-connect";
export function ConnectVaartoButton({ customerId }: { customerId: string }) { const { connect, ready, pending } = useVaartoConnect({ clientId: "vci_your_client_id", webhookUrl: `https://hooks.talkingtech.ai/vaarto/${customerId}`, });
async function onClick() { const result = await connect(); // null if they cancelled or closed the popup if (!result) return; await fetch("/integrations/vaarto/complete", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ code: result.code }), }); }
return ( <button onClick={onClick} disabled={!ready || pending}> {pending ? "Connecting…" : "Connect WhatsApp with Vaarto"} </button> );}Use the same vaarto-connect.ts and use-vaarto-connect.ts as the React tab, in a client
component. Exchange the code in a route handler, where the client secret stays on the server.
"use client";import { useVaartoConnect } from "./use-vaarto-connect";
export function ConnectVaartoButton({ customerId }: { customerId: string }) { const { connect, ready, pending } = useVaartoConnect({ clientId: process.env.NEXT_PUBLIC_VAARTO_CLIENT_ID!, webhookUrl: `https://hooks.talkingtech.ai/vaarto/${customerId}`, });
return ( <button disabled={!ready || pending} onClick={async () => { const result = await connect(); if (result) await fetch("/api/vaarto/complete", { method: "POST", body: JSON.stringify(result) }); }} > Connect WhatsApp with Vaarto </button> );}export async function POST(request: Request) { const { code } = await request.json();
const response = await fetch("https://vaarto.com/api/v1/connect/token", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ client_id: process.env.NEXT_PUBLIC_VAARTO_CLIENT_ID, client_secret: process.env.VAARTO_CLIENT_SECRET, code, }), }); if (!response.ok) return Response.json({ error: "Could not connect Vaarto" }, { status: 400 });
await saveVaartoConnection(await response.json()); // encrypt api_key and webhook.secret return new Response(null, { status: 204 });}Uses vaarto-connect.ts from the React tab (it has no React in it).
<script setup lang="ts">import { onMounted, ref } from "vue";import { loadVaartoConnect } from "./vaarto-connect";
const props = defineProps<{ customerId: string }>();const ready = ref(false);const pending = ref(false);
onMounted(() => loadVaartoConnect().then(() => (ready.value = true)));
async function onClick() { pending.value = true; try { const { code } = await window.VaartoConnect!.open({ clientId: import.meta.env.VITE_VAARTO_CLIENT_ID, webhookUrl: `https://hooks.talkingtech.ai/vaarto/${props.customerId}`, }); await fetch("/integrations/vaarto/complete", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ code }), }); } catch (error: any) { if (error.code !== "cancelled" && error.code !== "closed") alert(`Could not open Vaarto: ${error.code}`); } finally { pending.value = false; }}</script>
<template> <button :disabled="!ready || pending" @click="onClick">Connect WhatsApp with Vaarto</button></template>Uses vaarto-connect.ts from the React tab.
<script lang="ts"> import { onMount } from "svelte"; import { loadVaartoConnect } from "./vaarto-connect";
export let customerId: string; let ready = false;
onMount(() => loadVaartoConnect().then(() => (ready = true)));
async function onClick() { try { const { code } = await window.VaartoConnect!.open({ clientId: "vci_your_client_id", webhookUrl: `https://hooks.talkingtech.ai/vaarto/${customerId}`, }); await fetch("/integrations/vaarto/complete", { method: "POST", body: JSON.stringify({ code }) }); } catch { // cancelled, closed or popup_blocked } }</script>
<button disabled={!ready} on:click={onClick}>Connect WhatsApp with Vaarto</button>Uses vaarto-connect.ts from the React tab.
import { Component, Input, OnInit } from "@angular/core";import { HttpClient } from "@angular/common/http";import { loadVaartoConnect } from "./vaarto-connect";
@Component({ selector: "app-connect-vaarto", standalone: true, template: `<button [disabled]="!ready" (click)="onClick()">Connect WhatsApp with Vaarto</button>`,})export class ConnectVaartoComponent implements OnInit { @Input() customerId = ""; ready = false;
constructor(private http: HttpClient) {}
ngOnInit() { loadVaartoConnect().then(() => (this.ready = true)); }
async onClick() { try { const { code } = await window.VaartoConnect!.open({ clientId: "vci_your_client_id", webhookUrl: `https://hooks.talkingtech.ai/vaarto/${this.customerId}`, }); this.http.post("/integrations/vaarto/complete", { code }).subscribe(); } catch { // cancelled, closed or popup_blocked } }}VaartoConnect.open(options)
Section titled “VaartoConnect.open(options)”| Option | Required | Description |
|---|---|---|
clientId |
yes | Your client ID |
webhookUrl |
if you registered events | Where this customer’s events go. Must be https:// on one of your webhook domains. Put your own customer ID in the path or query so you know whose events they are |
state |
no | Any string up to 500 characters; returned unchanged. A random one is generated if you leave it out |
It resolves with { code, state }. It rejects with an error whose code is:
error.code |
Meaning |
|---|---|
cancelled |
The customer clicked Cancel |
closed |
The popup was closed before connecting |
popup_blocked |
The browser blocked the popup. Call open() directly from a click handler, with the script already loaded |
The code is only ever posted to your page’s own origin, and only if that origin is registered, so another site can’t intercept it.
If your site sets Cross-Origin-Opener-Policy
Section titled “If your site sets Cross-Origin-Opener-Policy”A Cross-Origin-Opener-Policy: same-origin header cuts the link between your page and the
popup, so the result never arrives and connect() ends with closed. Use
same-origin-allow-popups on the page with the button, or leave the header unset.
The popup protocol
Section titled “The popup protocol”connect.js is a thin wrapper around this. To implement it yourself (a native web view, a framework without script tags):
- Open, from a click:
https://app.vaarto.com/connect?client_id=…&origin=<your page's origin>&state=<random>&webhook_url=…(webhook_urlis optional; URL-encode every value.) - Listen for
messageevents onwindow. Accept only those whereevent.origin === "https://app.vaarto.com",event.data.type === "vaarto:connect"andevent.data.stateequals your state. event.data.codeis the code.event.data.error === "cancelled"means they cancelled. If the popup closes with no message, treat it as closed.
3. Exchange the code on your server
Section titled “3. Exchange the code on your server”POST https://vaarto.com/api/v1/connect/tokenContent-Type: application/json
{ "client_id": "vci_your_client_id", "client_secret": "vcs_your_client_secret", "code": "the code from the popup"}{ "connection_id": "0193f5c2-…", "workspace": { "id": "0193a1b0-…", "name": "Acme Retail" }, "api_key": "ck_live_a1b2c3d4_Xy9…", "scopes": ["WHATSAPP_SEND", "MESSAGES_READ"], "webhook": { "id": "0193f5c2-…", "url": "https://hooks.talkingtech.ai/vaarto/customer-123", "secret": "9f2c…", "events": ["MESSAGE_RECEIVED", "MESSAGE_STATUS"] }}webhook is null when your app has no events. This is the only time you see api_key
and webhook.secret. Store both, encrypted, against your customer.
app.post("/integrations/vaarto/complete", express.json(), async (req, res) => { const response = await fetch("https://vaarto.com/api/v1/connect/token", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ client_id: process.env.VAARTO_CLIENT_ID, client_secret: process.env.VAARTO_CLIENT_SECRET, code: req.body.code, }), });
if (!response.ok) return res.status(400).json({ error: "Could not connect Vaarto" });
const connection = await response.json(); await saveVaartoConnection(req.user.customerId, { connectionId: connection.connection_id, workspaceName: connection.workspace.name, apiKey: connection.api_key, // encrypt at rest webhookSecret: connection.webhook?.secret, // encrypt at rest });
res.sendStatus(204);});import os, requestsfrom flask import request
@app.post("/integrations/vaarto/complete")def complete_vaarto(): response = requests.post( "https://vaarto.com/api/v1/connect/token", json={ "client_id": os.environ["VAARTO_CLIENT_ID"], "client_secret": os.environ["VAARTO_CLIENT_SECRET"], "code": request.json["code"], }, timeout=10, ) if not response.ok: return {"error": "Could not connect Vaarto"}, 400
connection = response.json() save_vaarto_connection(current_customer_id(), connection) # encrypt api_key and webhook.secret return "", 204curl -X POST https://vaarto.com/api/v1/connect/token \ -H "Content-Type: application/json" \ -d '{"client_id":"vci_…","client_secret":"vcs_…","code":"…"}'Errors
Section titled “Errors”| Status | Message | What to do |
|---|---|---|
401 |
Invalid client credentials | Check the client ID and secret, and that your app is active |
400 |
This code is invalid or has expired | Codes last 5 minutes. Ask the customer to connect again |
400 |
This code has already been used | Each code works once. Don’t retry a successful exchange |
429 |
Too many requests | Back off and retry |
4. Use the credentials
Section titled “4. Use the credentials”The API key works exactly like one the customer created themselves:
curl https://vaarto.com/api/v1/messages/whatsapp \ -H "Authorization: Bearer ck_live_…" \ -H "Content-Type: application/json" \ -d '{"to":"+919876543210","text":"Hello from Talking Tech"}'See Send a message, and verify every webhook delivery with the secret as described in Webhooks.
Reconnecting
Section titled “Reconnecting”Connecting the same workspace to your app again replaces the earlier connection: its API key
is revoked and its webhook removed the moment the new code is exchanged. Always store the
latest api_key and webhook.secret; the old ones stop working.
If an exchange fails on our side, nothing is left half-made and the code stays usable, so you can retry it within its 5 minutes.
When a customer disconnects
Section titled “When a customer disconnects”Customers see your app under Settings → Connected apps in Vaarto. Disconnecting revokes
the API key and deletes the webhook immediately, so your calls start returning 401 with
an invalid-key error. Treat that as “disconnected” and show the Connect button again.
The key and webhook also appear on the customer’s API keys and Webhooks pages, named after your app. Revoking either there has the same effect on that part.
Checklist
Section titled “Checklist”- The client secret lives only on your server, never in your frontend or repo.
connect.jsis loaded before the click, andVaartoConnect.open()is called directly from the click with noawaitbefore it.- The button’s page doesn’t send
Cross-Origin-Opener-Policy: same-origin. - Your page’s origin (and
localhostwhile testing) is registered. - Each customer gets their own
webhookUrl, so you can tell their events apart. - You store
api_keyandwebhook.secretencrypted, and handle a401as a disconnect.