定制 chandachewe/whatsapp 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

chandachewe/whatsapp

Composer 安装命令:

composer create-project chandachewe/whatsapp

包简介

A PHP Package for Business Whatsapp API

README 文档

README

This package shows you how to make WhatsApp Business API requests from your PHP Project.

Requirements

  • PHP >= 8.1

Installation

Install this package using composer require:

composer require chandachewe/whatsapp 

Usage

Template Message

You need to create a template message from the whatsapp business API Developer Portal

require 'vendor/autoload.php';  
use Chandachewe\Whatsapp\Messages\TemplateMessage;

$templateMessage = new TemplateMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);

$response = $templateMessage->template(   
    'template_name',
    'language_code (optional)'
   
);

echo $response;

Your version should be rounded to one decimal place e.g v19.0 and not v19 The language code is optional here. If empty it will take the default as en_US

Send a Text Message

You can only send a template type message as your first message to a user. If you want to send a text message the user must first send a message to you or reply to any of the messages you sent.

<?php
require_once 'vendor/autoload.php';

use Chandachewe\Whatsapp\Messages\TextMessage;


$textMessage = new TextMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);

$response = $textMessage->text(   
    'You have to check out this amazing messaging package at https://github.com/chandachewe10/whatsapp-api'
   
);

echo $response;

Send a List Message

These are Messages including a menu of up to 10 options. This type of message offers a simpler and more consistent way for users to make a selection when interacting with a business.

<?php
require_once 'vendor/autoload.php';

use Chandachewe\Whatsapp\Messages\ListMessage;


$listMessage = new ListMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);

$response = $listMessage->list(   
    'Header',
    'Body Message',
    'Footer (Optional)',
    [
        'button' => 'title on drop down button',
        'sections' => [
            [
                'title' => 'first row title',
                'rows' => [
                    [
                        'id' => '100993900202',
                        'title' => 'Your heading',
                        'description' => 'Your description'
                    ]
                ],
               
                // You can add another title and row here 
                 ...
                
            ]
        ]
                    ]
                 
  
);

echo $response;

Send a Button option Message

These are Messages including up to 3 options —each option is a button. This type of message offers a quicker way for users to make a selection from a menu when interacting with a business.

<?php
require_once 'vendor/autoload.php';

use Chandachewe\Whatsapp\Messages\ButtonMessage;


$buttonMessage = new ButtonMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);

$response = $buttonMessage->button(
    'Header',
    'Body Message',
    'Footer (Optional)',
    [
        'buttons' => [
            [
                'type' => 'reply',
                'reply' => [
                    'id' => 'unique-postback-id',
                    'title' => 'your button title'
                ]
            ],
           
            // You can add another type and reply here 
                 ...
        ]
    ],
    'text',
    ''

);

echo $response;

Sometimes you may want to include the image in the header with button option(s) below the image. You can achieve this by using image instead of text and providing the image link. Hence your code will now be:

<?php
require_once 'vendor/autoload.php';

use Chandachewe\Whatsapp\Messages\ButtonMessage;


$buttonMessage = new ButtonMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);

$response = $buttonMessage->button(
    'Header',
    'Body Message',
    'Footer (Optional)',
    [
        'buttons' => [
            [
                'type' => 'reply',
                'reply' => [
                    'id' => 'unique-postback-id',
                    'title' => 'your button title'
                ]
            ],
           
            // You can add another type and reply here 
                 ...
        ]
    ],
    'image', // note that we have replaced text with image  
    'https://path_to_your_image' // note that we have added the image link 

);

echo $response;

Sometimes you may want to include the document in the header with button option(s) below the document. You can achieve this by using document instead of text and providing the document link. Hence your code will now be:

<?php
require_once 'vendor/autoload.php';

use Chandachewe\Whatsapp\Messages\ButtonMessage;


$buttonMessage = new ButtonMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);

$response = $buttonMessage->button(
    'Header',
    'Body Message',
    'Footer (Optional)',
    [
        'buttons' => [
            [
                'type' => 'reply',
                'reply' => [
                    'id' => 'unique-postback-id',
                    'title' => 'your button title'
                ]
            ],
           
            // You can add another type and reply here 
                 ...
        ]
    ],
    'document', // note that we have replaced text with document  
    'https://path_to_your_document' // note that we have added the document link 

);

echo $response;

Sometimes you may want to show a small video clip in the header with button option(s) below the video. You can achieve this by using video instead of text and providing the video link. Hence your code will now be:

<?php
require_once 'vendor/autoload.php';

use Chandachewe\Whatsapp\Messages\ButtonMessage;


$buttonMessage = new ButtonMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);

$response = $buttonMessage->button(
    'Header',
    'Body Message',
    'Footer (Optional)',
    [
        'buttons' => [
            [
                'type' => 'reply',
                'reply' => [
                    'id' => 'unique-postback-id',
                    'title' => 'your button title'
                ]
            ],
           
            // You can add another type and reply here 
                 ...
        ]
    ],
    'video', // note that we have replaced text with video  
    'https://path_to_your_video' // note that we have added the video link 

);

echo $response;

Send a Location Message

These Messages allows you to send your location address to your clients/customers.

<?php
require_once 'vendor/autoload.php';

use Chandachewe\Whatsapp\Messages\LocationMessage;


$locationMessage = new LocationMessage(
'v19.0',
'BUSINESS PHONE NUMBER ID',
'RECIPIENT PHONE NUMBER',
'TOKEN'
);

$response = $locationMessage->location(
    'Longitude',
    'Latitude',
    'Name of location ',
    'Address',
    'Body',
    'optional footer',
   [
        "name" => "send_location" 
   ]

);

echo $response;

chandachewe/whatsapp 适用场景与选型建议

chandachewe/whatsapp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 chandachewe/whatsapp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 chandachewe/whatsapp 我们能提供哪些服务?
定制开发 / 二次开发

基于 chandachewe/whatsapp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 16
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-03-19