六路径/Twilio包

包装Twilio SDK的Symfony包

安装: 208

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 1

开放问题: 0

类型:symfony-bundle

0.0.4 2017-11-02 14:02 UTC

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

这将发送任何排队消息,并选择删除或保留它们。