Giter Site home page Giter Site logo

->onConversation don't work about viber-bot-php HOT 7 OPEN

bogdaan avatar bogdaan commented on July 25, 2024
->onConversation don't work

from viber-bot-php.

Comments (7)

Bogdaan avatar Bogdaan commented on July 25, 2024

You write exact same code in "Don't work" and "Work")

from viber-bot-php.

l-e-m avatar l-e-m commented on July 25, 2024

sorry. misspelling. :)
Don't work
->onConversation(function ($event) use ($bot, $botSender, $log) {
$log->info('onConversation ');
return (new \Viber\Api\Message\Text())
->setSender($botSender)
->setText('same text');
})
and nothing in the logs

from viber-bot-php.

Bogdaan avatar Bogdaan commented on July 25, 2024

it looks like you forgot to init $log variable

from viber-bot-php.

l-e-m avatar l-e-m commented on July 25, 2024

did not forget.
$log = new Logger('bot');
$log->pushHandler(new StreamHandler('/tmp/bot.log'));
try {
$bot = new Bot(['token' => $apiKey]);
$bot
->
etc.

from viber-bot-php.

Bogdaan avatar Bogdaan commented on July 25, 2024

Check you webserver access_log and error_log.
If access_log not contains HTTP 200 for this request - try to find records inside error_log.

from viber-bot-php.

IgorUsoltsev avatar IgorUsoltsev commented on July 25, 2024

I don't know if this is a Lib bug or what

I had the same bug in Laravel app.

This change helped me in onConversation event:

$bot
    ->onConversation(function ($event) use ($bot, $botSender) {
        //I had to echo my json encoded message and die() to stop code execution. Nothing else returned the correct response
        echo json_encode($this->defaultMessage);
        die();
    })

from viber-bot-php.

NikitaKobzar avatar NikitaKobzar commented on July 25, 2024

У меня проблема так и осталась. Событие срабатывает, но обратное сообщение пользователю не отправляется в любом виде... Подскажите, в чем может быть проблема?

$bot = new Bot(['token' => $apiKey]);
    $bot
        ->onConversation(function ($event) use ($bot, $botSender, $log ) {

            $log->info('onConversation ' . var_export($event, true));

            $context = $event->getContext();
            if ($context != "" && $context != null) {
                add_with_referral($event->getSender()->getId(), $event->getSender()->getName(), $context);
            } else {
                add_user($event->getSender()->getId(), $event->getSender()->getName(), $log);
            }

            return (new \Viber\Api\Message\Text)
                ->setSender($botSender)
                ->setText("Can i help you?");
        })

from viber-bot-php.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.