1
0
mirror of synced 2024-11-25 05:06:02 +03:00
mg-bot-api-client-php/README.md

54 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2020-11-26 15:57:53 +03:00
[![Build Status](https://github.com/retailcrm/mg-bot-api-client-php/workflows/ci/badge.svg)](https://github.com/retailcrm/mg-bot-api-client-php/actions)
[![Coverage](https://img.shields.io/codecov/c/gh/retailcrm/mg-bot-api-client-php/master.svg?logo=codecov&logoColor=white)](https://codecov.io/gh/retailcrm/mg-bot-api-client-php)
2020-11-26 15:57:53 +03:00
[![Latest stable](https://img.shields.io/packagist/v/retailcrm/mg-bot-api-client-php.svg)](https://packagist.org/packages/retailcrm/mg-bot-api-client-php)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/retailcrm/mg-bot-api-client-php.svg?logo=php&logoColor=white)](https://packagist.org/packages/retailcrm/mg-bot-api-client-php)
2019-06-28 14:15:30 +03:00
2019-07-16 16:41:56 +03:00
# Message Gateway Bot API PHP client
2019-06-28 14:15:30 +03:00
## Requirements
2019-07-16 15:04:54 +03:00
* PHP 7.1 and above
2019-06-28 14:15:30 +03:00
* PHP's cURL support
* PHP's JSON support
## Install
1) Get [composer](https://getcomposer.org/download/)
2) Run into your project directory:
```bash
2019-07-16 15:56:44 +03:00
composer require retailcrm/mg-bot-api-client-php ~1.*
2019-06-28 14:15:30 +03:00
```
If you have not used `composer` before, include autoloader into your project.
```php
require 'path/to/vendor/autoload.php';
```
## Usage
### Assign dialog
```php
2019-07-16 16:41:56 +03:00
<?php
use RetailCrm\Common\Exception;
2019-06-28 14:43:11 +03:00
use RetailCrm\Mg\Bot\Client;
use RetailCrm\Mg\Bot\Model\Request\DialogAssignRequest;
2019-06-28 14:15:30 +03:00
$client = new Client('https://mg.url.demo', 'T9DMPvuNt7FQJMszHUd', true);
try {
$request = new DialogAssignRequest();
$request->setDialogId(60);
$request->setUserId(4);
2019-07-16 16:41:56 +03:00
/* @var \RetailCrm\Mg\Bot\Model\Response\AssignResponse $response */
2019-06-28 14:15:30 +03:00
$response = $client->dialogAssign($request);
2019-07-16 16:41:56 +03:00
} catch (Exception\LimitException | Exception\InvalidJsonException | Exception\UnauthorizedException $exception) {
2019-06-28 14:15:30 +03:00
echo $exception->getMessage();
}
2019-07-16 16:41:56 +03:00
echo $response->getPreviousResponsible();
2019-06-28 14:15:30 +03:00
```