承接 blackford/twilio-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

blackford/twilio-bundle

Composer 安装命令:

composer require blackford/twilio-bundle

包简介

Symfony 5+ / PHP 8+ wrapper for the official Twilio SDK v6+

关键字:

README 文档

README

About

A quick and easy way to use the Twilio SDK (version 6) in a Symfony based application. Support for PHP 8+, Symfony >= 5.4. For full documentation about how to use the Twilio Client, see the official SDK provided by Twilio.

This bundle is a small wrapper around the official sdk. It just adds the basic auth and configs and avoid that you have to configure your service.yaml manual.

If you are already using the symfony/notifier component, habe a look at twilio-notifier.

Thank you for the awesome work of Fridolin Koch who created the first version of this bundle, with support for version 4 of the SDK.

Installation

composer req blackford/twilio-bundle

Configuration

Add these 2 parameters in .env.local and set it to your twilio credentials. Please see Env-Variables for more details.

TWILIO_USER='!changeMe!'
TWILIO_PASSWORD='!changeMe!'

Add a new file config/packages/twilio.yml and copy and adjust the following content:

blackford_twilio:
  
  # (Required) Username to authenticate with, typically your Account SID from www.twilio.com/user/account
  username: '%env(TWILIO_USER)%'

  # (Required) Password to authenticate with, typically your Auth Token from www.twilio.com/user/account
  password: '%env(TWILIO_PASSWORD)%'
    
  # (Optional) Account Sid to authenticate with, defaults to <username> (typically not required)
  # accountSid: 
    
  # (Optional) Region to send requests to, defaults to no region selection (typically not required)
  # region: 

Usage

Configure your Twilio-Account

Provided services:

Service Class
twilio.client \Twilio\Rest\Client

Inside a controller:

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Twilio\Rest\Client as TwilioClient;

class TestController extends Controller
{
    public function __construct(private TwilioClient $twilioClient)
    {}
    
    public function smsAction()
    {
        $date = date('r');
        
        $message = $this->twilioClient->messages->create(
            '+12125551234', // Text any number
            array(
                'from' => '+14085551234', // From a Twilio number in your account
                'body' => "Hi there, it's $date and Twilio is working properly."
            )
        );

        return new Response("Sent message [$message->sid] via Twilio.");
    }
}

Inside a console command:

use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Twilio\Rest\Client as TwilioClient;

#[AsCommand(name: 'twilio:test:sms', description: 'Test the Twilio integration by sending a text message.')]
class TwilioTestCommand extends ContainerAwareCommand
{
    public function __construct(private TwilioClient $twilioClient)
    {}
    
    protected function execute(InputInterface $input, OutputInterface $output)
    {
         $date = date('r');
         
         $message = $this->twilioClient->messages->create(
             '+12125551234', // Text any number
             array(
                 'from' => '+14085551234', // From a Twilio number in your account
                 'body' => "Hi there, it's $date and Twilio is working properly."
             )
         );
        
        $output->writeln("Sent message [$message->sid] via Twilio.");
    }
}

Copyright / License

See LICENSE

统计信息

  • 总下载量: 45.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 44
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-27

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固