samiaraboglu/fb-messenger-api-bundle

Symfony Facebook Messenger Api Bundle

v4.4.0 2020-10-29 19:34 UTC

This package is auto-updated.

Last update: 2024-04-29 04:08:52 UTC


README

Use the Facebook Messenger PHP API.

Download the Bundle

$ composer require samiaraboglu/fb-messenger-api-bundle

Enable the Bundle

Registered bundles in the config/bundles.php file of your project:

return [
    // ...
    Samiax\FbMessengerApiBundle\FbMessengerApiBundle::class => ['all' => true],
    // ...
];

Config

Add this to config/packages/fb_messenger_api.yaml:

fb_messenger_api:
    access_token:   %fb_messenger_api_access_token%
    verify_token:   %fb_messenger_api_verify_token%

Example

Send text message:

namespace App\Controller\Messenger;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\Response;

use Samiax\FbMessengerApiBundle\Service\MessengerApi;

/**
 * Messenger Controller
 *
 * @Route("/messenger", name="app_messenger_")
 */
class MessengerController extends AbstractController
{
    /**
     * @Route("/send", name="send")
     *
     * @return Response
     */
    public function sendAction(MessengerApi $messengerApi)
    {
        $messenger = $messengerApi->messenger;

        $message = $messenger->message;

        $message->text('<MESSAGE_TEXT>');

        $messenger->send(<PSID>, $message);

        return new Response();
    }
}