kolinalabs/naty-whatsapp-sdk

Naty Secretary WhatsApp PHP SDK

1.0 2021-10-16 13:56 UTC

This package is not auto-updated.

Last update: 2024-09-19 12:33:14 UTC


README

Naty

Naty WhatsApp PHP SDK 是一个库,用于简化在API Naty中可用的资源的使用。

  • 获取您的连接(或断开连接)的WhatsApp号码。
  • 为断开连接的WhatsApp号码启动会话。
  • 上传文件,获取用于在消息中发送的mediaKey。
  • 向联系人列表发送个性化消息。

安装

composer require kolinalabs/naty-whatsapp-sdk

使用

use KolinaLabs\NatyApi;

$naty = new NatyApi('<your-naty-api-token>');

// Get whatsapp numbers with status
$whatsapps = $naty->whatsapps();

// Get specific whatsapp (eg: $whatsapps[0])
$whatsapp = current($whatsapps);

if (!$whatsapp) {
  die('No connection returned.');
}

if(!$whatsapp->isConnected()) {
  $status = $naty->connect($whatsapp);
}

$messages = [
  [
    'number' => '<whatsapp-number-here>',
    'name' => '<your contact name>',
    'body' => "Your custom message *Hello* 😎!\n" .
      "Text with line breaks is also *accepted*:\n\n" .
      "👍 *Instagram*: https://www.instagram.com/kolina.labs \n" .
      "👎 *Website*: https://kolinalabs.com",
    // 'mediaKey' => $mediaKey,
    // 'mediaType' => 'image'
  ],
  //... more messages here
];

// Send messages - Method 1
$result = $naty->messages($whatsapp, $messages);

// Send messages - Method 2
$result = $whatsapp->send($messages);

更多信息请参阅示例