IntegrationsIntermediate

How to Send an AI Welcome Message When Someone Opens Your Viber Bot

Handle the conversation_started event so new Viber users get an AI-generated greeting instantly.

7 minIntermediate

First impressions matter. Viber fires a conversation_started event the moment a user opens your bot, before they type anything. Replying in that window with a friendly, on-brand greeting boosts subscription rates. Here you will craft that greeting with AI and return it the way Viber expects.

What you need

  • A working Viber bot with a set webhook (see the Viber bot guide)
  • The conversation_started event in your event_types list
  • Node 18+ and an AI API key
Reply in the response body
For conversation_started you must return the message in the HTTP response itself, not by calling send_message. The user is not a subscriber yet, so the send endpoint would fail.

Step 1: Add the event to your webhook

Re-run set_webhook with conversation_started added so Viber notifies you when a user opens the chat.

zsh - viber-welcome
$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","conversation_started"]}'
{"status":0,"status_message":"ok"}
$

Step 2: Generate and return the greeting

When the event type is conversation_started, ask the model for a short welcome that fits your brand, then send it back directly in res.json. Use the user's name from the payload to make it personal.

server.js
app.post("/viber", async (req, res) => {
  if (req.body.event === "conversation_started") {
    const name = req.body.user?.name || "there";

    const out = await ai.chat.completions.create({
      model: "gpt-5-mini",
      messages: [
        {
          role: "system",
          content:
            "Write a one sentence warm welcome for a support bot. Address the user by name.",
        },
        { role: "user", content: `The user is named ${name}.` },
      ],
    });

    return res.json({
      type: "text",
      text: out.choices[0].message.content,
    });
  }

  res.sendStatus(200);
  // ... handle "message" events as before
});
Viber - first open
Agent
Hi Maria, welcome! I am your AI helper, ask me anything and I will get you sorted right away.
The greeting appears before the user types anything.
Keep a fallback ready
If the model call is slow or errors, return a static greeting instead of nothing. An empty response means the user sees a blank, broken bot.

Result

New users now get a personalized AI greeting the instant they open your bot, which nudges more of them to subscribe and start a real conversation.

Watch related tutorials

Tags
#viber#onboarding#welcome#ai#webhook