retailcrm / mg-bot-api-client-php

MG Bot API的PHP客户端

v1.4.11 2024-09-16 12:29 UTC

README

Build Status Coverage Latest stable PHP from Packagist

消息网关机器人API PHP客户端

需求

  • PHP 7.3及以上
  • PHP的cURL支持
  • PHP的JSON支持

安装

  1. 获取composer

  2. 在你的项目目录下运行

composer require retailcrm/mg-bot-api-client-php ~1.*

如果你之前没有使用过composer,请将自动加载器包含到你的项目中。

require 'path/to/vendor/autoload.php';

用法

分配对话

<?php

use RetailCrm\Common\Exception;
use RetailCrm\Mg\Bot\Client;
use RetailCrm\Mg\Bot\Model\Request\DialogAssignRequest;

$client = new Client('https://mg.url.demo', 'T9DMPvuNt7FQJMszHUd', true);

try {
    $request = new DialogAssignRequest();
    $request->setDialogId(60);
    $request->setUserId(4);

    /* @var \RetailCrm\Mg\Bot\Model\Response\AssignResponse $response */
    $response = $client->dialogAssign($request);
} catch (Exception\LimitException | Exception\InvalidJsonException | Exception\UnauthorizedException $exception) {
    echo $exception->getMessage();
}

echo $response->getPreviousResponsible();