在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):aloha/laravel-twilio开源软件地址(OpenSource Url):https://github.com/aloha/laravel-twilio开源编程语言(OpenSource Language):PHP 100.0%开源软件介绍(OpenSource Introduction):laravel-twilioLaravel Twilio API Integration InstallationBegin by installing this package through Composer. Run this command from the Terminal: composer require aloha/twilio This will register two new artisan commands for you:
And make these objects resolvable from the IoC container:
There's a Facade class available for you, if you like. In your 'Twilio' => 'Aloha\Twilio\Support\Laravel\Facade', You can publish the default config file to php -r "copy('vendor/aloha/twilio/src/config/config.php', 'config/twilio.php');" FacadeThe facade has the exact same methods as the use Twilio; To send a message using the default entry from your Twilio::message($user->phone, $message); One extra feature is that you can define which settings (and which sender phone number) to use: Twilio::from('call_center')->message($user->phone, $message);
Twilio::from('board_room')->message($boss->phone, 'Hi there boss!'); Define multiple entries in your UsageCreating a Twilio object. This object implements the $twilio = new Aloha\Twilio\Twilio($accountId, $token, $fromNumber); Sending a text message: $twilio->message('+18085551212', 'Pink Elephants and Happy Rainbows'); Creating a call: $twilio->call('+18085551212', 'http://foo.com/call.xml'); Generating a call and building the message in one go: $twilio->call('+18085551212', function (\Twilio\TwiML\VoiceResponse $message) {
$message->say('Hello');
$message->play('https://api.twilio.com/cowbell.mp3', ['loop' => 5]);
}); or to make a call with any Twiml description you can pass along any Twiml object: $message = new \Twilio\TwiML\VoiceResponse();
$message->say('Hello');
$message->play('https://api.twilio.com/cowbell.mp3', ['loop' => 5]);
$twilio->call('+18085551212', $message); Access the configured $sdk = $twilio->getTwilio(); You can also access this via the Facade as well: $sdk = Twilio::getTwilio(); Pass as many optional parameters as you wantIf you want to pass on extra optional parameters to the $twilio->message($to, $message, $mediaUrls, $params);
// passes all these params on. The same is true for the call method. $twilio->call($to, $message, $params);
// passes all these params on. Dummy classThere is a dummy implementation of the Logging decoratorThere is one more class available for you: the By default the service providers don't wrap objects with the if (getenv('APP_ENV') === 'production') {
$twilio = $container->make(\Aloha\Twilio\Manager::class);
} else {
$psrLogger = $container->make(\Psr\Log\LoggerInterface::class);
$twilio = new LoggingDecorator($psrLogger, new \Aloha\Twilio\Dummy());
}
// Inject it wherever you want.
$notifier = new Notifier($twilio); CreditsLicenselaravel-twilio is open-sourced software licensed under the MIT license |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论