Giter Site home page Giter Site logo

telegram-bot-api's Introduction

telegram Telegram Bot API PHP

A PHP wrapper for the Telegram Bot API.

Latest Stable Version Total Downloads License

Composer package available.

Requirements

  • PHP 5.5 or higher
  • cURL
  • Telegram app (mobile or desktop)

Get started

You will find everything you need to know to use this API in the wiki

Installation

$ composer require mgp25/telegram-bot-api

My Bots :)

@life_quotes_bot - Receive a life quote daily at 12pm (Central European Time Zone)

What is Telegram?

According to Telegram:

Telegram is a messaging app with a focus on speed and security, it’s super fast, simple and free. You can use Telegram on all your devices at the same time — your messages sync seamlessly across any of your phones, tablets or computers.

With Telegram, you can send messages, photos, videos and files of any type (doc, zip, mp3, etc), as well as create groups for up to 200 people. You can write to your phone contacts and find people by their usernames. As a result, Telegram is like SMS and email combined — and can take care of all your personal or business messaging needs.

May. 2015: 2 billion messages daily, ~62 million Monthly Active Users.

License

MIT

telegram-bot-api's People

Contributors

feltkamptv avatar gojigeje avatar mgp25 avatar rflsouza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

telegram-bot-api's Issues

method sendPhoto doesn't work

Hello

method sendPhoto() NOT work. i first get $chat_id from message and after this, want to send single photo whit this syntax :

$tg->sendPhoto($chat_id , 'http://i.investopedia.com/dimages/graphics/binary.jpg') ;

other things like $tg and $chat_id and sendMessage() is OK but this method doesn't work

please help me!

Uncaught exception 'PDOException'

hi iam follow your tutorial, i am developing on hosting server...
but get problem on Uncaught exception 'PDOException'

here is the error response of server.

: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1 no such table: contacts' in /home/test/public_html/Telegram-Bot-API-master/examples/quoteBot.php:61 Stack trace: #0 /home/test/public_html/Telegram-Bot-API-master/examples/quoteBot.php(61): PDO->prepare('SELECT chat_id ...') #1 /home/test/public_html/Telegram-Bot-API-master/examples/quoteBot.php(25): addContact(115906090) #2 {main} thrown in /home/test/public_html/Telegram-Bot-API-master/examples/quoteBot.php on line 61

how can i fix it? thanks

method delete message

Hello! really miss the next method :)

 /**
  * Use this method to delete a message.
  *
  * @link https://core.telegram.org/bots/api#deletemessage
  *
  * @param int            $chat_id
  * @param int            $message_id
  *
  * @return Array
  */
 public function deleteMessage($chat_id, $message_id)
 {
   $params = compact('chat_id', 'message_id');

   return $this->sendRequest('deleteMessage', $params);
 }

Clarification on usage

Hi I saw this API just now. But I am a little confused how to use it. I read the wiki but cannot understand how to "start a conversation with @Botfather". Also I cannot understand what is chat_id and how to get it. Also do I need to provide my phone number is this API for authentication? Please explain. Thank you

Violation of License! Copied Code.

It seems like you copied a lot of code and violated the License. I don't think its a good idea to take credits for others work.

You should consider giving proper credit and follow the license.

Copy message from other channel

Hi
Sorry,I have a question about your project(telegram).
Can I get the message channels that I'm not their admin?
I want write a script that read message from other chanel and write to
my chanel.
I can do it?
best regards
thanks

exampleFunctional

Hi I wants send simple massage(for example hi) to my but i dont know how use from my HTTP API(102***462:AAFlpWrP-p6euiLfbc0C93LMW***OBLxFxU) so in below(part1) i send my exampleFunctional.php pleas check what is my problem? and my error_log in cpanel show fatel error that i send you in part 2

part1:

<?php

require '../src/Telegram.php';

//                                       //
///////// CONFIG YOUR BOT'S TOKEN /////////
$token = "102***462:AAFlpWrP-p6euiLfbc0C93LMW***OBLxFxU";
$tg = new telegramBot($token);

$chat_id      = 'alihyazdi';
$guessed      = false;
$sendQuestion = false;


// Custom keyboard
$customKeyboard = [
    ['7', '8', '9'],
    ['4', '5', '6'],
    ['1', '2', '3'],
         ['0']
];
$reply_markup = $tg->replyKeyboardMarkup($customKeyboard, true, true);

do
{
  // Get updates the bot has received
  // Offset to confirm previous updates
  $updates = $tg->pollUpdates($offset);
  if ($updates['ok'])
  {
    foreach($updates['result'] as $data)
    {
        if (is_null($chat_id))
          $chat_id = $data['message']['chat']['id'];

        if (!$sendQuestion)
        {
          // sends an action 'typing'
          $tg->sendChatAction($chat_id, 'typing');

          // send message with a custom reply markup
          $tg->sendMessage($chat_id, 'Guess the number', false, null, $reply_markup);
          $sendQuestion = true;
        }

        if (($data['message']['text']) == 5)
        {
          $tg->sendChatAction($chat_id, 'typing');
          $tg->sendMessage($chat_id, 'You did it! :)');

          $tg->sendChatAction($chat_id, 'upload_photo');
          $tg->sendPhoto($chat_id, 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/718smiley.png/220px-718smiley.png');
          $guessed = true;
        }
        else
          $tg->sendMessage($chat_id, 'Wrong number :/ try again', false, null, $reply_markup);
    }
    $offset = $updates['result'][count($updates['result']) - 1]['update_id'] + 1;
  }
}
while(!$guessed);
$offset  = $updates['result'][count($updates['result']) - 1]['update_id'] + 1;
$updates = $tg->pollUpdates($offset);

part2:

[06-Aug-2015 01:00:24 UTC] PHP Fatal error:  Uncaught exception 'TelegramException' with message 'Required "token" key not supplied' in /home/hosseiny/public_html/telegram/src/Telegram.php:15
Stack trace:
#0 /home/hosseiny/public_html/telegram/examples/exampleFunctional.php(7): telegramBot->__construct(NULL)
#1 {main}
  thrown in /home/hosseiny/public_html/telegram/src/Telegram.php on line 15
[06-Aug-2015 01:00:27 UTC] PHP Fatal error:  Uncaught exception 'TelegramException' with message 'Required "token" key not supplied' in /home/hosseiny/public_html/telegram/src/Telegram.php:15
Stack trace:
#0 /home/hosseiny/public_html/telegram/examples/exampleFunctional.php(7): telegramBot->__construct(NULL)
#1 {main}
  thrown in /home/hosseiny/public_html/telegram/src/Telegram.php on line 15

Missing Methods

getChat, getChatAdministrators, getChatMembersCount, getChatMember, leaveChat

sendAudio from local storage

I have a problem sending audio files from my local storage

Warning: file_get_contents(https://api.telegram.org/botXXXXXXXX/sendAudio?chat_id=-XXXXXX&audio=storage%2Faudio.mp3): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request
 in /data/data/com.termux/files/home/bot/vendor/mgp25/telegram-bot-api/src/Telegram.php on line 465

Call Stack:
    0.0009     402672   1. {main}() /data/data/com.termux/files/home/bot/telegram.php:0
    5.0816     540080   2. telegramBot->sendAudio(???, ???, ???, ???, ???, ???, ???) /data/data/com.termux/files/home/bot/telegram.php:34
    5.0818     540456   3. telegramBot->sendRequest(???, ???) /data/data/com.termux/files/home/bot/vendor/mgp25/telegram-bot-api/src/Telegram.php:137
    5.0819     540616   4. file_get_contents(???) /data/data/com.termux/files/home/bot/vendor/mgp25/telegram-bot-api/src/Telegram.php:465

Here is my code

     else if(preg_match('/^\/audio/', strtolower($msg['text']))) {
          $telegram->sendAudio(
              $msg['chat']['id'],
              'storage/audio.mp3'
          );
      }

Add CURLOPT_RETURNTRANSFER to uploadFile()

I suggest to add

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

to the function uploadFile(). Otherwhise the message data (id. etc) will not be returned by the CURL operation if CURLOPT_RETURNTRANSFER is not set to 1 by default in the PHP enviroment.

Token

Hi there, i just downloaded your Api but...

What is Token or where can i find it?

I have App api_id, App api_hash, Public keys but i cannot find it.

Can you help me.

Thank you.

Send photo is not working

Hi, Im trying to use the api to send a picture, but is not working correctly. I try a local file on the server on the same place as the script, in anotehr folder or directly the url to the image getting the same result.
My test page looks like this:

require 'Telegram.php';
// initialise variables here
$chat_id = "9999999";

$token = "11111111111:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; // HERE YOUR TOKEN
//////////////////////////////////////////////////
echo "-#################################### \n ";
echo "# Telegram CLIENT # \n ";
echo "####################################- \n \n";

$tg = new telegramBot($token);

echo "Get Bot Information:\n";
$updates = $tg->getMe();
echo json_encode($updates) . "\n"; //<-- all ok

$tg->sendMessage($chat_id, "Working?");//<-- text message ok
$tg->sendChatAction($chat_id, 'upload_photo');//<-- action its ok

$tg->sendPhoto($chat_id, 'https://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/718smiley.png/220px-718smiley.png'); //<-- nothing happend / local file same result

Request 400 Error

Everything works fine, until I chat with the bot, it came out 400 error.

C:\xampp\htdocs\whatsapp\v3\telegram\examples>php exampleFunctional.php
####################################
#          Telegram CLIENT         #
####################################

Get Bot Information:
{"ok":true,"result":{"id":17######56,"first_name":"NickBot","username":"Nick147_b
ot"}}

Fatal error: Call to undefined function finfo_open() in C:\xampp\htdocs\whatsapp
\v3\telegram\src\Telegram.php on line 440

http request failed

hi i just used the getme and got this err:

Warning: file_get_contents(https://api.telegram.org/bot<token>\getMe?): failed to open stream: HTTP request failed! HTTP/1.1 502 Bad Gateway in C:\xampp\htdocs\testbot\vendor\mgp25\telegram-bot-api\src\Telegram.php on line 364

<?php

require "vendor/mgp25/telegram-bot-api/src/telegram.php";
$token = "<token>";
$tg = new TelegramBot($token);


$tg->getMe();

?>

Instant Reply

Hey, i have a question. Currently i have to open the webpath the bot is at. Is there a way to make it reply automatically when triggered via command?

getUserProfilePhotos error

Hello, there is a coding error in the function getUserProfilePhotos

In the line 294 where it says $param should read $params

Thank you

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.