IntegrationsIntermediate

How to Build an AI Auto-Reply Viber Bot

Create a Viber Public Account bot, set its webhook, and answer messages with AI over the REST API.

10 minIntermediate

Viber bots run on a Public Account and a simple REST API: you set a webhook, receive a JSON event for each message, and POST a reply. This guide creates the bot, registers the webhook, and wires incoming messages to an LLM so it answers automatically.

What you need

  • A Viber account and a Public Account created at partners.viber.com
  • The bot authentication token from the account info page
  • A public HTTPS endpoint (Viber requires a valid certificate)
  • Node 18+ and an AI API key

Step 1: Get your bot token

Sign in at partners.viber.com, create a bot account, and copy the token from the account info screen. Every API call carries this token in the X-Viber-Auth-Token header.

Viber Admin Panel - Account Info
Account name: AI Helper
URI: ai-helper
Token: 4f8e1c2a-....-bot [ Copy ]
The token is your only credential for the REST API.

Step 2: Set the webhook

Tell Viber where to send events by calling set_webhook once. The event_types array controls which events you receive; message is the one you care about. Viber will reject any URL without a valid SSL certificate.

zsh - viber-bot
$curl -X POST https://chatapi.viber.com/pa/set_webhook \
$ -H "X-Viber-Auth-Token: $VIBER_TOKEN" \
$ -d '{"url":"https://x9y8z7.ngrok.io/viber","event_types":["message"]}'
{"status":0,"status_message":"ok"}
$
status 0 means success
Viber returns status 0 for ok. Any other number is an error and status_message tells you why, for example a bad certificate or wrong token.

Step 3: Reply with AI

Each inbound message arrives as a POST with event: message. Read sender.id and message.text, generate an answer, and POST it back to send_message. Respond 200 quickly so Viber does not retry.

server.js
import "dotenv/config";
import express from "express";
import OpenAI from "openai";

const ai = new OpenAI();
const TOKEN = process.env.VIBER_TOKEN;
const app = express();
app.use(express.json());

app.post("/viber", async (req, res) => {
  res.sendStatus(200);
  if (req.body.event !== "message") return;

  const userId = req.body.sender.id;
  const text = req.body.message.text;

  const out = await ai.chat.completions.create({
    model: "gpt-5-mini",
    messages: [{ role: "user", content: text }],
  });

  await fetch("https://chatapi.viber.com/pa/send_message", {
    method: "POST",
    headers: {
      "X-Viber-Auth-Token": TOKEN,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      receiver: userId,
      type: "text",
      text: out.choices[0].message.content,
    }),
  });
});

app.listen(3000, () => console.log("Viber bot on :3000"));

Step 4: Subscribe and test

A user must say hi to your Public Account first; Viber then sends a conversation_started event and the user becomes a subscriber. After that, every message they send flows through your webhook.

Viber - chat with AI Helper
You
Translate good morning into Italian
Agent
Buongiorno.
The bot answers any subscriber instantly.

Result

Your Viber Public Account now answers subscribers with AI. Deploy the server somewhere with a real certificate and Viber will keep delivering events without you touching the webhook again.

Watch related tutorials

Tags
#viber#webhook#bot#ai#express