Git Product home page Git Product logo

laravel-telegram's Introduction

LaravelTelegram

A simple and lightweight Laravel 4.2 and Laravel 5.* wrapper to interact with Telegram Bot.

Get Started:

  • First of all, you should create a Telegram Bot, you can use Bot Father to do that;
  • Create a Telegram chat room (group) and add the Bot to this group, now the Bot can send messages!
  • After publish the package, open the telegram config file and provide all the required information.

Installation

  1. The Laravel Telegram Service Provider can be installed via ...
composer require ricardofontanelli/laravel-telegram:1.0 

or Composer by requiring the ricardofontanelli/laravel-telegram package in your project's composer.json

{
    "require": {
        "ricardofontanelli/laravel-telegram": "1.0"
    }
}

Then run a composer update

php composer update
  1. To use the Laravel Telegram Service Provider, you must register the provider when bootstrapping your application. If you are using Laravel >= 5.5, the package supports Automatic Package Discovery, skip to the step 3.

In Laravel find the providers key in your config/app.php and register the Laravel Telegram Service Provider.

    'providers' => array(
        // ...
        'RicardoFontanelli\LaravelTelegram\TelegramServiceProvider',
    )

Find the aliases key in your config/app.php and add the Laravel Telegram facade alias.

    'aliases' => array(
        // ...
        'Telegram' => 'RicardoFontanelli\LaravelTelegram\TelegramFacade',
    )
  1. After that, run the command above to publish the Telegram config file, you must provide your Telegram Bot credentials and chat room information.

Publishing the package

Now, you should publish the package to generate the config file, after that, edit the config file with your Telegram Bot credentials.

Laravel 4.2

The config file will be generate here: app/config/packages/ricardofontanelli/laravel-telegram/config.php

php artisan config:publish ricardofontanelli/laravel-telegram

Laravel 5.*

The config file will be generate here: app/config/telegram.php

php artisan vendor:publish --provider="RicardoFontanelli\LaravelTelegram\TelegramServiceProvider"

Send a message:

Now you can use it by php artisan tinker and run:

// Send a message
Telegram::sendMessage('default', 'Here we go!');
// or async
Telegram::async()->sendMessage('default', 'Here we go!');

The first value is the config key name of the chat/group id where the Bot will publicate the message, you can provide the chat/group id directly.

Get information about the Bot:

// Send an async message
Telegram::getMe()->getResult();

Get Bot update:

// Send an async message
Telegram::getUpdates()->getResult();

Other methods:

The class has use a magic method to call unsuported methods:

$params = ['method'=>'GET'];
Telegram::getWebhookInfo($params)->getResult()

You can use the variable $params to send query parameters and define the HTTP method (according the Telegram Bot Api documentation).

Find more:

You can find more here (Telegram Bot API)[https://core.telegram.org/bots/api], but if you need to call a method that the class doesn't support, feel free to send a PR.

laravel-telegram's People

Contributors

max13 avatar ricardofontanelli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.