shadowbane/laravel-whatsmeow
Composer 安装命令:
composer create-project shadowbane/laravel-whatsmeow
包简介
Send Simple WhatsApp message via Whatsmeow API
README 文档
README
About
This package provides easy integration with Whatsmeow, my own API for sending WhatsApp message.
Installation
install the package via composer:
composer require shadowbane/laravel-whatsmeow
Publishing Config
php artisan vendor:publish --provider="Shadowbane\Whatsmeow\WhatsmeowServiceProvider"
Usage
Configuration
add the following value to your .env file
WHATSMEOW_ENDPOINT= WHATSMEOW_TOKEN= WHATSAPP_NUMBER_FIELD= WHATSAPP_NUMBER_JSON_FIELD= DEBUG_WHATSAPP_NUMBER=
WHATSMEOW_ENDPOINT
Fill it with the url for Wablas API Endpoint.
WHATSMEOW_TOKEN
This is the token generated from your Wablas account.
WHATSAPP_NUMBER_FIELD
This is where you store the user's WhatsApp number in users table.
WHATSAPP_NUMBER_JSON_FIELD
only fill this if you store user's WhatsApp number on JSON column in database, for example, the data might look like this:
{"whatsapp": 0123456}
DEBUG_WHATSAPP_NUMBER
This is used when your APP_ENV is set to 'local' to prevent sending it to real user. It will send to debug number instead.
Sending Text Message
You can send text message using 'via' method inside notification class.
app/notifications/WhatsAppNotification:
namespace App\Notifications; use Illuminate\Notifications\Notification; use Shadowbane\Whatsmeow\Exceptions\FailedToSendNotification; use Shadowbane\Whatsmeow\WhatsmeowChannel; use Shadowbane\Whatsmeow\WhatsmeowMessage; class WhatsappNotification extends Notification { protected string $phoneNumber; protected string $message; /** * Create a new notification instance. * * @param string $phoneNumber * @param string $message; * * @return void */ public function __construct(string $phoneNumber, string $message) { $this->phoneNumber = $phoneNumber; $this->message = $message; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * * @return array */ public function via($notifiable) { return [WhatsmeowChannel::class]; } /** * @param $notifiable * * @throws FailedToSendNotification * * @return WhatsmeowMessage */ public function toWhatsapp($notifiable) { return WhatsmeowMessage::create() ->to($this->phoneNumber) ->content($this->message); } }
Change token
If your application has multiple token for multiple purpose, you can chain token($token) method to your WhatsmeowMessage instance
use Shadowbane\Whatsmeow\WhatsmeowMessage; ... public function toWhatsapp($notifiable) { return WhatsmeowMessage::create() ->token('this-is-another-token-in-my-application') ->to($this->phoneNumber) ->content($this->message); }
Send Using The Notifiable Trait
If you want to send it via notifiable, you can refer to this example:
namespace App\Notifications; use Illuminate\Notifications\Notification; use Shadowbane\Whatsmeow\WhatsmeowChannel; use Shadowbane\Whatsmeow\WhatsmeowMessage; class WhatsappNotification extends Notification { protected string $phoneNumber; protected string $message; /** * Create a new notification instance. * * @param string $message; * * @return void */ public function __construct(string $message) { $this->message = $message; } /** * Get the notification's delivery channels. * * @param mixed $notifiable * * @return array */ public function via($notifiable) { return [WhatsmeowChannel::class]; } /** * @param $notifiable * * @return WhatsmeowMessage */ public function toWhatsapp($notifiable) { return WhatsmeowMessage::create() ->content($this->message); } }
Then, you can trigger it with:
use App\Notifications\WhatsappNotification; $user->notify(new WhatsappNotification($message));
Sending to Multiple Users
This packages allows array to be passed as parameter in to() methods.
As Wablas allows comma-separated values as phone number, we automatically implode the array, and send it as comma-separated value to Wablas API.
Example:
use Shadowbane\Whatsmeow\WhatsmeowMessage; ... public function toWhatsapp($notifiable) { return WhatsmeowMessage::create() ->token('this-is-another-token-in-my-application') ->to([$destination1, $destination2]) ->content($this->message); }
If you prefer to send it to notifiables, you can send it via notification facade.
use Illuminate\Support\Facades\Notification; use App\Models\User; use App\Notifications\WhatsappNotification; Notification::send(User::whereSomeCondition(1)->get(), new WhatsappNotification(123) );
Notes
If you send it to notifiable, please make sure your WHATSAPP_NUMBER_FIELD reflecting the field where you store your user's WhatsApp number.
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security related issues, please send email to adly.shadowbane@gmail.com instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
shadowbane/laravel-whatsmeow 适用场景与选型建议
shadowbane/laravel-whatsmeow 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 153 次下载、GitHub Stars 达 5, 最近一次更新时间为 2022 年 04 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「whatsapp」 「whatsmeow」 「gomeow」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 shadowbane/laravel-whatsmeow 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 shadowbane/laravel-whatsmeow 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 shadowbane/laravel-whatsmeow 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
WhatsApp Latest CLoud API Wrapper for PHP
Alfabank REST API integration
The PHP WhatsApp library
Cliente Wis SDK para PHP
Laravel SDK for WhatsApp API Gateway - A comprehensive package for integrating WhatsApp messaging capabilities into Laravel applications
fuel price monitor provides a web dashboard and a configurable update notifier
统计信息
- 总下载量: 153
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2022-04-07