Coder Social home page Coder Social logo

telegram_bot's Introduction

Basic Telergam Bot (php)

This is a simple example of telegram bot using php without any dependencies. Can work with HTTP proxy.

Installation

Your site have to use https protocol.

  1. Copy files on your site
  2. Open in browser file bot.php
  3. Open dialog with @BotFather (https://t.me/BotFather) in your telegram client
  4. Send /newbot command
  5. Enter your bot title
  6. Enter your bot name (ex: @test_bot)
  7. Copy token to clipboard
  8. Paste token to form in browser and submit form
  9. Edit test_bot.php, paste token and bot name
  10. Talk to your bot

New in version 1.2

Inline Keyboards support and callbacks for inline buttons

New in API supports

  1. answerCallbackQuery() method - Reaction of inline keyboard click
  2. deleteMessage() method - Deleting message
  3. editMessageText() method - Editing message

New Bot functions

  1. callbackAnswer() method - Answer method on click for inline button
  2. callback_default() method - Default callback for inline button

New in version 1.1

  1. sendAudio() method - sends audio file with audioplayer (20Mb max)
  2. HTTP proxy support.

Customizing bot

Create commands you want in TestBot class

var $commands = [
  "/start" => "cmd_start",
  "/help" => "cmd_help",
  "/hi" => "cmd_hi"
];

Create methods for commands

function cmd_hi(){
  $this->api->sendMessage( "Hi, @" . $this->result["message"]["from"]["username"] . "." );
}

Api methods not implemented

If you want to call telegram API-method not implemented in this repo (i.e. sendLocation: https://core.telegram.org/bots/api#sendlocation) you can call it like this:

$params = [
  'chat_id' => 123,
  'latitude' => 0,
  'longitude' => 0
];
$this->api->call("sendLocation", $params);

Example bot

example_bot.php - example of the telegram bot, demonstrating main features of this repo. Sorry of russian comments. Test this bot you can here: http://t.me/kpg_test_bot (http://t.kpg.me/kpg_test_bot if blocked t.me)

telegram_bot's People

Contributors

webportnoy avatar

Watchers

 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.