PHP code example of distilleries / messenger
1. Go to this page and download the library: Download distilleries/messenger library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
distilleries / messenger example snippets
$this->app->singleton('Distilleries\Messenger\Contracts\MessengerReceiverContract', function ($app) {
return new MyMessengerClass();
});
class MyMessengerClass implements MessengerContract
{
public function receivedAuthentication($event)
{
$senderID = $event->sender->id;
Messenger::sendTextMessage($senderID, "Authentication successful");
}
public function receivedMessage($event)
{
$senderID = $event->sender->id;
Messenger::sendTextMessage($senderID, 'Test');
Messenger::sendImageMessage($senderID, env('APP_URL') . '/assets/images/logo.png');,
Messenger::sendCard($senderID, [
'template_type' => 'generic',
'elements' => [
[
"title" => "Messenger Boilerplate",
"image_url" => env('APP_URL') . '/assets/images/logo.png',
"subtitle" => "example subtitle",
'buttons' => [
[
'type' => "web_url",
'url' => "https://github.com/Distilleries/lumen-messenger-boilerplate",
'title' => "Come download it!"
]
]
]
]
]);
}
public function receivedDeliveryConfirmation($event)
{
$senderID = $event->sender->id;
Messenger::sendTextMessage($senderID, 'Test');
}
public function receivedPostback($event)
{
$senderID = $event->sender->id;
Messenger::sendTextMessage($senderID, 'Test');
}
}
Messenger::sendTextMessage($senderID, "Authentication successful");
Messenger::sendImageMessage($senderID, env('APP_URL') . '/assets/images/logo.png');
Messenger::getCurrentUserProfile($senderID);
Messenger::sendCard($senderID, [
'template_type' => 'generic',
'elements' => [
[
"title" => "Messenger Boilerplate",
"image_url" => env('APP_URL') . '/assets/images/logo.png',
"subtitle" => "example subtitle",
'buttons' => [
[
'type' => "web_url",
'url' => "https://github.com/Distilleries/lumen-messenger-boilerplate",
'title' => "Come download it!"
]
]
]
]
]);
php
$app->register(Distilleries\Messenger\MessengerLumenServiceProvider::class);
php
'providers' => [
\Distilleries\Messenger\MessengerServiceProvider::class,
]
php
'aliases' => [
'Messenger' => 'Distilleries\Messenger\Facades\Messenger'
]