Skip to content

Commit

Permalink
Instructions are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya S. Zobenko committed Aug 24, 2019
1 parent 7ddf4dd commit 5d03f1b
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ Tools set for messenger managing. Allows you to send any content via Telegram, V
Install the latest version with

```bash
// Not published on Packagist yet
$ composer require he110/communication-tools
```

Expand Down Expand Up @@ -72,6 +71,40 @@ $pool->sendScreen($screen);

```


### Work with events
```php
<?php

// Telegram client's taken as an example. You can use other
use He110\CommunicationTools\Telegram\Messenger;
use He110\CommunicationTools\Request;
use He110\CommunicationTools\MessengerUser;

$messenger = new Messenger();
$messenger->setAccessToken(YOUR_TOKEN_HERE);

// Action for simple incoming messages
$messenger->onMessage(function(Request $request) use ($messenger) {
// Your code here...
$text = $request->getMessage();
/** @var MessengerUser $user $user */
$user = $request->getUser();
$messenger->setTargetUser($user->getUserId());
$messenger->sendMessage("We've got your message: '$text'");
});

// Action for buttons click
$messenger->onButtonClick(function(Request $request) use ($messenger) {
// Your code here...
$payload = $request->getPayload();
});

// Required!!! Run this method to check if events are triggered
$messenger->checkEvents();

```

## About

### Requirements
Expand Down

0 comments on commit 5d03f1b

Please sign in to comment.