Telegram-bot-sdk: deleteMessage

Created on 23 May 2017  路  3Comments  路  Source: irazasyed/telegram-bot-sdk

I didn't find any implementation for deleteMessage described here.
Please consider this method in next release.
BTW, is there any method to call custom api function in SDK?
For example,
public function customMethod(array $params)
and use it for new methods like deleteMessage.

Most helpful comment

@zvermafia

__call has two arguments. The first one method name and deleteMessage in your case.
The second is an array of array containing method params. chat_id and message_id in your case.
So you could call __call for your deleteMessage like this:

Telegram::__call('deleteMessage', [['chat_id' => $yourChatId, 'message_id' => $yourMessageId]])

Consider the datatype of second argument as Array of Array (^_^)

All 3 comments

I found protected function post($endpoint, array $params = [], $fileUpload = false) in source code.
But I think converting it to public function is more useful.
I appreciate it in advance

Edit:
I found another public method to call it for custom methods.

public function __call($method, $arguments)

It solved my problem!

@khalilst I don't understand how did you solve it! Please explain me (I need to use deleteMessage).

Yes the __call method in the class Telegram\Bot\Api is public, but it processes only actions with the get prefix?!:

public function __call($method, $arguments)
{
    $action = substr($method, 0, 3);
    if ($action === 'get') {
        /* @noinspection PhpUndefinedFunctionInspection */
        $class_name = studly_case(substr($method, 3));
        $class = 'Telegram\Bot\Objects\\'.$class_name;
        $response = $this->post($method, $arguments[0] ?: []);

        if (class_exists($class)) {
            return new $class($response->getDecodedBody());
        }

        return $response;
    }

    return false;
}

@zvermafia

__call has two arguments. The first one method name and deleteMessage in your case.
The second is an array of array containing method params. chat_id and message_id in your case.
So you could call __call for your deleteMessage like this:

Telegram::__call('deleteMessage', [['chat_id' => $yourChatId, 'message_id' => $yourMessageId]])

Consider the datatype of second argument as Array of Array (^_^)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

b10585 picture b10585  路  4Comments

corneyl picture corneyl  路  3Comments

maminbajand picture maminbajand  路  4Comments

Enelar picture Enelar  路  3Comments

jahanzaibbahadur picture jahanzaibbahadur  路  4Comments