CasperLaiTW / laravel-fb-messenger

Laravel Facebook Messenger Provider
MIT License
105 stars 27 forks source link

Send messages via queue #82

Closed webappbuilder closed 7 years ago

webappbuilder commented 7 years ago

Hello! Please provide example how to implement sending replies via queue?

CasperLaiTW commented 7 years ago

Hi

if you want to sending replies via queue, I think you have to create a job and chatbot class.

Chatbot


namespace App;

use Casperlaitw\LaravelFbMessenger\Contracts\BaseHandler;

class Chatbot extends BaseHandler
{
    public function __construct()
    {
        $this->createBot(config('fb-messenger.app_token'));
    }

   /**
     * Handle the chatbot message
     *
     * @param ReceiveMessage $message
     *
     * @return mixed
     */
    public function handle(ReceiveMessage $message)
    {
        return false;
    }
}

Job

then you can use chatbot to send message. like this.

use Casperlaitw\LaravelFbMessenger\Messages\Text;
use App\Chatbot;

$chatbot = new Chatbot;
$text = new Text($senderId, 'Text');
$chatbot->send($text);
CasperLaiTW commented 7 years ago

Hi @webappbuilder, is it solved?

webappbuilder commented 7 years ago

Hi, thank you. I solved this earlier. I understand how to use queues with laravel. But I have to write custom send function for Jobs: `$api = new Bot(config("fb-messenger.app_token"));

$api->setSecret(config("fb-messenger.app_secret"));

$api->setDebug(null);` because of debug uses request class.

CasperLaiTW commented 7 years ago

Hi

if you don't need to debug, you don't call $api->setDebug(null);

if you didn't setup debug, bot will ignore call debug function

webappbuilder commented 7 years ago

Okay, i got it. Thanks. I mean I can't use plugin with debug turned on in config within console command or queue. You can close issue if it's proper functionality.

letanhienth92 commented 5 years ago

I get an error: 'Parameter error: You cannot send messages to this id'. Please help me

CasperLaiTW commented 5 years ago

@letanhienth92 Can you provide more specific issue you get? some code and some logs.

I can't get any hint from your error message.

Thanks