Doesn't work Welcome message to New User in Viber Bot 'conversation_started'

397 Views Asked by At

I try to send a welcome message to a new unsigned user, but it doesn't work. Please, help how solve this problem? This code doesn't work:

elseif($input['event'] == 'conversation_started') {
//    "tracking_data" = "tracking data",
    $data['tracking_data'] = $tracking_data;
    $message['type'] = "text";
    $message['text'] = 'Text to new user';
    $message['keyboard'] = [
        "Type" => "keyboard",
        "DefaultHeight" => true,
        "Buttons" => [[
            "ActionType" => "reply",
            "ActionBody" => "main_menu",
            "Text" => "Main menu",
            "TextSize" => "regular"
        ]]
    ];
}
1

There are 1 best solutions below

0
On

As viber documentation stated, user must be subscribed in order for bot to send any kind of message.

An approach to your problem is:

  1. Create a JSON file to store userProfiles.
  2. You should check inside onConversationStarted() if the userProfile is subscribed.
  3. If yes, then use bot.sendMessage() to send your welcome message.

Please check how Viber Documentation API works!