六路径 / Twilio包
包装Twilio SDK的Symfony包
0.0.4
2017-11-02 14:02 UTC
Requires
- php: >=7.1
- six-paths/components: 0.0.1
- symfony/framework-bundle: ~2.8
- twilio/sdk: 5.15.3
Requires (Dev)
- phpunit/phpunit: ~5
This package is auto-updated.
Last update: 2024-09-04 23:22:48 UTC
README
安装
手动安装
将以下内容添加到您的composer.json文件中
"require": { "six-paths/twilio-bundle": "dev-master" }
自动安装
composer require six-paths/twilio-bundle@dev-master
在app/AppKernel.php
中激活该包
$bundles = array( // ... new Sixpaths\TwilioBundle\SixpathsTwilioBundle(), );
配置
将以下内容添加或包含在您的config.yml
参数中
sixpaths.twilio.username: <account sid> sixpaths.twilio.password: <auth token> sixpaths.twilio.spool.enabled: true sixpaths.twilio.spool.type: file sixpaths.twilio.spool.directory: '%kernel.root_dir%/../app/twilio/spool/' sixpaths.twilio.spool.retain: true sixpaths.twilio.from: '<phone number>' sixpaths.twilio.defaults.to: '<phone number>'
使用
建议将此服务注入到监听器或其他可能需要消费它的服务中,而不是使用控制器中的 $this->get('...');;然而,此选项仍然可用
作为控制器的一部分
class SomeController extends Controller { public function someAction(/* ...$arguments */) { $twilio = $this->get('sixpaths.twilio'); $messages = $twilio->messages; $message = $messages->create( '+441234567890', // Send a message to this number [ 'from' => '+449876543210', // Send the message from this number 'body' => 'Message Body', // The message to send ] ); } }
作为控制台命令的一部分
class SomeCommand extends ContainerAwareCommand { protected function configure() { $this->setName('some:command') ->setDescription('A command'); } protected function execute(InterInterface $input, OutputInterface $output) { $container = $this->getContainer(); $twilio = $container->get('sixpaths.twilio'); $messages = $twilio->messages; $message = $messages->create( '+441234567890', // Send a message to this number [ 'from' => '+449876543210', // Send the message from this number, 'body' => 'Message Body', // The message to send ] ); } }
命令
此包包含两个打包的命令。
sixpaths:twilio:spool:message:generate
这将允许您生成消息 - 无论是排队还是其他 - 以确认设置。这些消息将被发送到默认电话号码(sixpaths.twilio.defaults.to
)
sixpaths:twilio:spool:message:send
这将发送任何排队消息,并选择删除或保留它们。