autodeal / laravel-cmtext-whatsapp
CM.com textclient,用于laravel应用的whatsapp通道
0.1.0
2022-06-09 19:15 UTC
Requires
- php: ^7.2.5|^8.0
- cmdotcom/text-sdk-php: ^2.1
- friendsofphp/php-cs-fixer: ^2.16
- laravel/framework: ^7.0|^8.0|^9.0
Requires (Dev)
- orchestra/testbench: 5.*
- phpunit/phpunit: ^8.5|^9.3.3
This package is not auto-updated.
Last update: 2024-09-28 03:55:30 UTC
README
本项目使用Composer来管理依赖。因此,在安装此包之前,请确保您的机器上已安装Composer。
运行以下命令
composer --version
whatsapp通道用于发送通知
安装
使用composer安装包
composer require autodeal/laravel-cmtext-whatsapp
将包含的配置发布到config/cmtext.php
php artisan vendor:publish --tag=config
将PRODUCT_TOKEN_WHATSAPP添加到项目的.env文件中,值应该是您的API Key产品
如何使用它
使用以下命令创建一个新的通知文件php artisan make:notification TestNotification 创建此类后,您必须在其中实现所需的逻辑。
例如,考虑TestNotification类,很好,现在我们想要我们的通知向用户发送短信。为了实现这一点,我们将添加我们的通知以使用我们新的驱动程序,这是在via方法中完成的。
<?php
namespace App\Notifications;
use Autodeal\WhatsAppChannel;
use Autodeal\WhatsAppMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class PruebaNotification extends Notification
{
use Queueable;
public function via($notifiable)
{
// So instead of the "default" mail channel.. Lets change or add our notification to notify user with the WhatsAppChannel class.
// We also need to import our WhatsAppChannel at the top of our file for this to work.
return [WhatsAppChannel::class];
// return ['mail', WhatsAppChannel::class]; both channels
}
}
现在我们还需要指定WhatsAppChannel需要接收什么来发送whatsapp。例如,一个电话号码和一条消息。这是通过在Notification中调用toWhatsapp()方法而不是默认的toMail()方法来完成的。
代码示例
<?php
namespace App\Notifications;
use Autodeal\WhatsAppChannel;
use Autodeal\WhatsAppMessage;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class PruebaNotification extends Notification
{
use Queueable;
public function via($notifiable)
{
return [WhatsAppChannel::class];
}
public function toWhatsapp($notifiable)
{
return (new WhatsAppMessage)
->lineText('Message text')
->to(['1239493042'])
->templateId('id_templa_into_cm_platform')
->templateName('test_name_template')
->parameters([
'tex'
]);
}
}
安全性
如果您发现任何安全问题,请通过电子邮件联系felipe@autodeal.mx或giovanny@autodeal.mx我们