简体   繁体   中英

Botman telegram events not hitting

I'm trying to welcome users on the group, I have following code in my handle() method -

public function handle(Request $request)
{
    $botman = app('botman');

    $botman->on('new_chat_members', function($payload, $bot) {
        $bot->reply($payload);
    });

    $botman->hears('/help', function ($bot) {

        $result = '/hi - hello';

        $bot->reply($result,  [
            'parse_mode' => 'Markdown'
        ]);
    });

    $botman->fallback(function ($bot) {
        $bot->reply("Sorry, I did not understand these commands. Try: /help");
    });

    $botman->listen();
}

But I dont see anything if I add anyone to the group. Am I missing anything here?

I found the problem. This line $bot->reply($payload); was the problem. I'm new to PHP, Laravel and Botman. I think, it could not send the object as reply. Once replaced it with

$bot->reply($payload[0]['first_name']);

it worked. I could at least see first name of the user who join the group.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM