php-telegram-bot / core

PHP Telegram Bot based on the official Telegram Bot API
MIT License
3.9k stars 953 forks source link

how to get text/message from bot using hook? #122

Closed adamramadhan closed 8 years ago

adamramadhan commented 8 years ago

hello, ive setup an hook, but there is no docs available for doing something like this maybe?

      try {
          // Create Telegram API object
          $telegram = new \Longman\TelegramBot\Telegram($API_KEY, $BOT_NAME);

          // Handle telegram webhook request
          $object = $telegram->handle();

          // get get everything bot sees.
          echo $object->getallmessages/eveythingupdate()? 

      } catch (\Longman\TelegramBot\Exception\TelegramException $e) {
          // Silence is golden!
          // log telegram errors
          // echo $e;
      }

or something like

exports.run = function (bot) {

    bot.on('text', function (message) {

        console.log(message);
    });
};

from node-telegram-api ?

i need to get all the text from at my chat group or private chat that to the bot or bot knows. (yes i already set the permission)

MBoretto commented 8 years ago

Hello, https://github.com/akalongman/php-telegram-bot/blob/master/src/Commands/SystemCommands/GenericmessageCommand.php

Here you can simply implement what you are looking for. All messages as photo, text, stickers.. are handled by this. This command don't handle: text starting with '/' like /commands.

For redirecting everthing you should code deep in the library

adamramadhan commented 8 years ago

i see, can we overwrite them? we already made it work by making a folder, just in case i dont want to mess anything in my vendors folder (as im using laravel)

      $telegram->addCommandsPath(__DIR__ .'/Telegram');

then

made a file example/forcereply, works great!,

  1. can we make a GenericmessageCommand.php in /Telegram folder to overwrite the default command?
  2. how do we debug? or log? ive already use $telegram->setLogRequests(true); and it works, but it doest show why my new custom command doesn't work, maybe theres an error in line x, how do you currently do the debugging?
  3. how can we disable and enable certain kinds system command? like //$telegram->setCommandConfig('NewchatparticipantCommand', ['active' => 'false]` or maybe easier to overwrite them and edit to disable them?

btw thanks @Mboretto for this awesome work.

MBoretto commented 8 years ago

Yes sure, overwriting the Generic message commands you will also remove the conversation feature. If you are interested in you should re-implement this logic in your extended command.

I would suggest you to use getUpdatescli to develop and then move to webhooks when everythings work.

We've plan to develop the enable/disable command feature https://github.com/akalongman/php-telegram-bot/issues/93. If you don't want touch your vendor you can overwrite all the commands using EmptyServerResponse function: https://github.com/akalongman/php-telegram-bot/blob/master/src/Commands/SystemCommand.php#L31

;) Thanks!