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.
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.
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.
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.
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.
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
5:42
24:16
33:42
41:18
28:05
3:12