waapi/waapi-laravel-sdk 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

waapi/waapi-laravel-sdk

最新稳定版本:v1.1.0

Composer 安装命令:

composer require waapi/waapi-laravel-sdk

包简介

WaAPI Laravel Package

README 文档

README

Latest Version on Packagist Total Downloads

Laravel Package to use with waapi.app.

Installation

You can install the package via composer:

composer require waapi/waapi-laravel-sdk

You can publish the config file with:

php artisan vendor:publish --tag="waapi-config"

This is the contents of the published config file:

return [
    'api_token' => env('WAAPI_API_TOKEN'),
    'instance_id' => env('WAAPI_INSTANCE_ID'),
];

Please adapt your .env with your instance ID and Token which can be obtained from your API Tokens

Replace with your token and your instance ID

WAAPI_API_TOKEN=abcdefghijkl123456789
WAAPI_INSTANCE_ID=123

Usage

$waAPI = new WaAPI\WaAPI();
$waAPI->sendMessage('1222333444@c.us', 'Hello there!');

Webhook Listener

The package provides a webhooks endpoint to handle incoming webhooks. Simply update your instance with the event types you want to listen to and the endpoint.

Make sure your app is running on a publicly availabel domain. Locally the webhooks won't work.

app(WaAPI::class)->updateInstance(
    route('waapi.webhooks'),
    [
        EventType::MESSAGE->value,
        EventType::QR->value
    ]
);

Create an event listener to listen on the webhook events

new Message example:

php artisan make:listener WaAPIMessageListener --event=\\WaAPI\\WaAPI\\Events\\MessageEvent

QR Code change example:

php artisan make:listener WaAPIQrCodeListener --event=\\WaAPI\\WaAPI\\Events\\QrEvent

Register your listener in app/Providers/EventServiceProvider.php if autodiscovery for events is disabled

    use App\Listeners\WaAPIInstanceReadyListener;
    use App\Listeners\WaAPIMessageListener;
    use WaAPI\WaAPI\Events\MessageEvent;
    use WaAPI\WaAPI\Events\QrEvent;
        
    [...]
        
    protected $listen = [
        MessageEvent::class => [
            WaAPIMessageListener::class,
        ],
        QrEvent::class => [
            WaAPIQrCodeListener::class,
        ],
    ];

Example for WaAPIMessageListener:

<?php

namespace App\Listeners;

use WaAPI\WaAPI\Events\MessageEvent;
use WaAPI\WaAPI\WaAPI;

class WaAPIMessageListener
{
    /**
     * Handle the event.
     */
    public function handle(MessageEvent $message): void
    {
        if (!$message->isFromMe()) {
            app(WaAPI::class)->sendMessage($message->getFrom(), 'Hello to you too!');
        }
    }
}

Available events:

AuthenticatedEvent
AuthFailureEvent
DisconnectedEvent
GroupJoinEvent
GroupLeaveEvent
GroupUpdateEvent
InstanceReadyEvent
LoadingScreenEvent
MediaUploadedEvent
MessageAcknowledgedEvent
MessageCreatedEvent
MessageEvent
MessageReactionEvent
MessageRevokedEveryoneEvent
MessageRevokedMeEvent
QrEvent
StateChangeEvent

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

License

The MIT License (MIT). Please see License File for more information.

统计信息

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

GitHub 信息

  • Stars: 9
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-21