pouler/facebook-messenger-bundle
Composer 安装命令:
composer create-project pouler/facebook-messenger-bundle
包简介
A Symfony bundle for Facebook Messenger
README 文档
README
A PHP Facebook Messenger API for the Symfony framework.
Installation
Step 1: Download Bundle
$ composer require pouler/facebook-messenger-bundle
Step 2: Enable the bundle (Symfony 2/3)
Next, enable the bundle in the kernel:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new PouleR\FacebookMessengerBundle\FacebookMessengerBundle(), ); }
Configuration
Edit your config.yml with the following configuration:
pouler_facebook_messenger:
app_id: 'YourFBMessengerAppId'
app_secret: 'YourFBMessengerAppSecret'
Examples
Set your default greeting text
$service = new FacebookMessengerService('...', '...', new NullLogger()); $service->setAccessToken('PAGE_ACCESS_TOKEN'); $config = new GreetingTextConfiguration(); $config->setText('Hello and welcome!'); $service->setGreetingText($config);
Send a text message to a user (by PSID)
$service = new FacebookMessengerService('...', '...', new NullLogger()); $service->setAccessToken('PAGE_ACCESS_TOKEN'); $recipient = new Recipient('PSID'); $message = new Message('Hi there, this is a test'); $service->postMessage($recipient, $message);
Use batch requests to send a text message to different users (by PSID)
$service = new FacebookMessengerService('...', '...', new NullLogger()); $service->setAccessToken('PAGE_ACCESS_TOKEN'); $message = new Message('Hi there, this is a batch message'); $service->addMessageToBatch(new Recipient('PSID1'), $message); $service->addMessageToBatch(new Recipient('PSID2'), $message); $service->addMessageToBatch(new Recipient('PSID3'), $message); $response = $service->sendBatchRequests(); // The response variable contains an array with FailedMessageRequest objects
Create a generic template message
$message = new Message(); $templateAttachment = new TemplateAttachment(); $genericTemplatePayload = new GenericTemplatePayload(); $pbButton = new PostbackButton(); $pbButton->setTitle('Button Title Goes Here'); $pbButton->setPayload('payload_data'); $wuButton = new WebUrlButton(); $wuButton->setTitle('Button Title Goes Here'); $wuButton->setUrl('https://www.google.com'); $buttons = [$pbButton, $wuButton]; // Create some elements $genericElementOne = new GenericElement(); $genericElementOne->setTitle('Element Title Goes Here'); $genericElementOne->setImageUrl('https://placekitten.com/200/300'); $genericElementOne->setSubtitle('Subtitle Goes Here'); $genericElementOne->setButtons($buttons); $genericElementTwo = new GenericElement(); $genericElementTwo->setTitle('Element Title Goes Here'); $genericElementTwo->setImageUrl('https://placekitten.com/200/300'); $genericElementTwo->setSubtitle('Subtitle Goes Here'); $genericElementTwo->setButtons($buttons); // Add them to the payload $genericTemplatePayload->setElements([$genericElementOne, $genericElementTwo]); // Set the payload on the attachment $templateAttachment->setPayload($genericTemplatePayload); // Set the Attachment on the message $message->setAttachment($templateAttachment);
Original project by John Kosmetos (https://github.com/jkosmetos/facebook-messenger-api)
统计信息
- 总下载量: 11.28k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-08-16