silasrm/chat-api
Composer 安装命令:
composer require silasrm/chat-api
包简介
Chat API Notifications channel for Laravel 5.6+
README 文档
README
Introduction
This package makes it easy to send notifications using Chat API with Laravel 5.6+.
First of all: contract or get your free demo account and setup your Whatsapp number: Whatsapp authentication process
Contents
Installation
You can install the package via composer:
$ composer require silasrm/chat-api
Setting up the Chat API service
In order to send message to Whatsapp using Chat API, you need to authenticate your number using QR Code on API.
Add your Chat API url and token to your config/services.php:
// config/services.php ... 'chatapi' => [ // Like: https://euXXXX.chat-api.com/instanceYYYYY/ 'url' => env('CHATAPI_URL'), 'token' => env('CHATAPI_TOKEN'), ], ...
Usage
You can use the channel in your via() method inside the notification:
use Illuminate\Notifications\Notification; use Silasrm\ChatApi\ChatApiMessage; use Silasrm\ChatApi\ChatApiChannel; class OrderCreated extends Notification { public function via($notifiable): array { return [ ChatApiChannel::class, ]; } public function toRocketChat($notifiable): ChatApiMessage { return ChatApiMessage::create('John Doe create a new order with value US$ 50.0') ->to('NNNNNNNNNNNNNN'); // Phone number with country code } }
In order to let your notification know which Chat API phone number you are targeting, add the routeNotificationForChatApi method to your Notifiable model:
public function routeNotificationForChatApi(): string { return $this->phone; }
Available methods
to(): Specifies the phone number to send the notification to (overridden by routeNotificationForChatApi if empty).
content(): Sets a content of the notification message. Supports pure text, UTF-8 or UTF-16 string with emoji.
attachment(): This will add an single attachment.
attachments(): This will add multiple attachments.
link(): This will add an single link.
links(): This will add multiple links.
Adding Attachment
There are several ways to add one ore more attachments to a message
public function toChatApi($notifiable) { return ChatApiMessage::create('Test message') ->to('NNNNNNNNNNNNNN') // Phone number with country code ->attachments([ // url (for remote) or path (for local), file ChatApiAttachment::create()->url('test'), ChatApiAttachment::create(['url' => 'test']), new ChatApiAttachment(['url' => 'test']), ['url' => 'test'] ]); }
Available methods
caption(): The text caption for this attachment.
filename(): Name of this file. If empty, use the original name of file.
[
[
'caption' => 'Caption of file',
'filename' => 'payment.xlsx',
]
];
Adding Link
There are several ways to add one ore more links to a message
public function toChatApi($notifiable) { return ChatApiMessage::create('Test message') ->to('NNNNNNNNNNNNNN') // Phone number with country code ->links([ ChatApiLink::create() ->url('https://wikimedia.org/nature') ->title('All about Nature') ->previewImage('https://upload.wikimedia.org/wikipedia/ru/3/33/NatureCover2001.jpg'), ChatApiLink::create([ 'url' => 'https://wikimedia.org/nature', 'title' => 'All about Nature', 'previewImage' => 'https://upload.wikimedia.org/wikipedia/ru/3/33/NatureCover2001.jpg', ]), new ChatApiLink([ 'url' => 'https://wikimedia.org/nature', 'title' => 'All about Nature', 'previewImage' => 'https://upload.wikimedia.org/wikipedia/ru/3/33/NatureCover2001.jpg', ]), [ 'url' => 'https://wikimedia.org/nature', 'title' => 'All about Nature', 'previewImage' => 'https://upload.wikimedia.org/wikipedia/ru/3/33/NatureCover2001.jpg', ] ]); }
Available methods
title(): The title of link. Required.
previewImage(): The image url/path of link preview. Required.
description(): The description for this link.
[
[
'title' => 'All about Nature',
'previewImage' => 'https://upload.wikimedia.org/wikipedia/ru/3/33/NatureCover2001.jpg',
'description' => 'See that!',
]
];
Changelog
Please see CHANGELOG for more information what has changed recently.
Testing
$ vendor/bin/phpunit
Security
If you discover any security related issues, please email silasrm@gmail.com instead of using the issue tracker.
Contributing
Please see CONTRIBUTING for details.
Credits
Change log
Please see CHANGELOG for more information on what has changed recently.
License
The MIT License (MIT). Please see License File for more information.
silasrm/chat-api 适用场景与选型建议
silasrm/chat-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 73 次下载、GitHub Stars 达 5, 最近一次更新时间为 2020 年 05 月 31 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「chat」 「laravel」 「whatsapp」 「Chat-API」 「notification-channel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 silasrm/chat-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 silasrm/chat-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 silasrm/chat-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
This simple PHP class allows you to easily generate Smartsupp.com JS chat code.
Client for the REST API plugin of the OpenFire Server
Captures outgoing SMS notifications
The Yii2 extension module to chat registered users.
统计信息
- 总下载量: 73
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 5
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-05-31