├── .gitignore ├── composer.json ├── src └── Component.php ├── LICENSE.md └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # phpstorm project files 2 | .idea 3 | 4 | # netbeans project files 5 | nbproject 6 | 7 | # windows thumbnail cache 8 | Thumbs.db 9 | 10 | # composer vendor dir 11 | /vendor 12 | 13 | # composer itself is not needed 14 | composer.phar 15 | 16 | # composer lock file 17 | composer.lock 18 | 19 | # Mac DS_Store Files 20 | .DS_Store -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sonko-dmitry/yii2-telegram-bot-api", 3 | "description": "Telegram bot api component for Yii2", 4 | "type": "yii2-extension", 5 | "keywords": ["telegram", "bot", "api", "yii", "yii2"], 6 | "license": "BSD-3-Clause", 7 | "homepage": "http://github.com/SonkoDmitry/yii2-telegram-bot-api", 8 | "authors": [ 9 | { 10 | "name": "Sonko Dmitry", 11 | "email": "st.difor@gmail.com" 12 | } 13 | ], 14 | "require": { 15 | "yiisoft/yii2": "*", 16 | "telegram-bot/api": "*" 17 | }, 18 | "autoload": { 19 | "psr-4": { 20 | "SonkoDmitry\\Yii\\TelegramBot\\": "src" 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/Component.php: -------------------------------------------------------------------------------- 1 | apiToken)) { 30 | throw new Exception('Bot token cannot be empty'); 31 | } 32 | 33 | parent::__construct($this->apiToken); 34 | } 35 | } -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Telegram bot api for Yii2 is free software. It is released under 2 | the terms of the following BSD License. 3 | 4 | Copyright © 2015 by Dmitry Sonko. All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions 8 | are met: 9 | 10 | * Redistributions of source code must retain the above copyright 11 | notice, this list of conditions and the following disclaimer. 12 | * Redistributions in binary form must reproduce the above copyright 13 | notice, this list of conditions and the following disclaimer in 14 | the documentation and/or other materials provided with the 15 | distribution. 16 | * The names of the copyright holders and contributors may not be 17 | used to endorse or promote products derived from this software 18 | without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 22 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 23 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 24 | COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 25 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 26 | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 28 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 | POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Telegram bot API for Yii2 2 | ================ 3 | [![Packagist](https://img.shields.io/packagist/l/sonko-dmitry/yii2-telegram-bot-api.svg)](https://github.com/SonkoDmitry/yii2-telegram-bot-api/blob/master/LICENSE.md) 4 | [![Dependency Status](https://www.versioneye.com/user/projects/55bb59406537620017001a32/badge.svg?style=flat)](https://www.versioneye.com/user/projects/55bb59406537620017001a32) 5 | [![Packagist](https://img.shields.io/packagist/v/sonko-dmitry/yii2-telegram-bot-api.svg)](https://packagist.org/packages/sonko-dmitry/yii2-telegram-bot-api) 6 | [![Packagist](https://img.shields.io/packagist/dt/sonko-dmitry/yii2-telegram-bot-api.svg)](https://packagist.org/packages/sonko-dmitry/yii2-telegram-bot-api) 7 | 8 | This extension is the way to integrate [telegram-bot/api](https://packagist.org/packages/telegram-bot/api) wrapper with your Yii2 application. 9 | 10 | Installation 11 | ------------ 12 | The preferred way to install this extension is through [composer](http://getcomposer.org/download/). 13 | 14 | To install, either run 15 | ``` 16 | $ php composer.phar require sonko-dmitry/yii2-telegram-bot-api:* 17 | ``` 18 | or add 19 | ``` 20 | "sonko-dmitry/yii2-telegram-bot-api": "*" 21 | ``` 22 | to the `require` section of your `composer.json` file. 23 | 24 | 25 | Usage 26 | ----- 27 | 0. Add the component configuration in your *global* `main.php` config file: 28 | ```php 29 | 'components' => [ 30 | 'bot' => [ 31 | 'class' => 'SonkoDmitry\Yii\TelegramBot\Component', 32 | 'apiToken' => 'YOUR_BOT_API_TOKEN', 33 | ], 34 | ], 35 | ``` 36 | 37 | 0. Now you can use component 38 | ```php 39 | \Yii::$app->bot->sendMessage(1234567, 'Hello world!'); 40 | ``` 41 | Where "1234567" receiver telegram id or chat id. --------------------------------------------------------------------------------