GithubHelp home page GithubHelp logo

9feed / communication-tools Goto Github PK

View Code? Open in Web Editor NEW

This project forked from he110/communication-tools

0.0 0.0 0.0 422 KB

Tools set for messenger managing. Allows you to send any content via Telegram, Viber, WhatsApp, VK and so on.

License: MIT License

PHP 100.00%

communication-tools's Introduction

Communication Tools Build Status

Latest Stable Version codecov Maintainability

Tools set for messenger managing. Allows you to send any content via Telegram, Viber, WhatsApp, VK, Facebook Messenger and so on.

Installation

Install the latest version with

$ composer require he110/communication-tools

Basic Usage

Messenger's clients

<?php

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

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

// If you want, to send simple text message
$messenger->sendMessage("Your message text here");

// To send image use method sendImage
$messenger->sendImage("path/to/file", "(Optional) Your text description");
// or, to send document...
$messenger->sendDocument("path/to/file", "(Optional) Your text description");
// you can also send voice files
$messenger->sendVoice("path/to/file");

// If you wanna use buttons, it's better way to use MessengerScreen
$screen = new MessengerScreen();
$screen->addMessage("Your message text here");
$screen->addButtonText("Text button");
$screen->addButtonLink("URL button", "https://google.com");
$messenger->sendScreen($screen);

Multiple messengers

<?php

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

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

// Pool allows you to use multiple messengers as one
$pool = new MessengerPool();
$pool->add($messenger);

$pool->sendMessage("Your message text here");

// If you wanna use buttons, it's better way to use MessengerScreen
$screen = new MessengerScreen();
$screen->addMessage("Your message text here");
$screen->addButtonText("Text button");
$screen->addButtonLink("URL button", "https://google.com");
$pool->sendScreen($screen);

Work with events

<?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

  • Communication Tools works with PHP 7.2 or above.

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub

Author

Ilya S. Zobenko - [email protected] - http://twitter.com/he110_todd

License

"Communication Tools" is licensed under the MIT License - see the LICENSE file for detail

communication-tools's People

Contributors

he110 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.