Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Which method is use to send messages? #38

Closed
Ham3D opened this issue Sep 19, 2015 · 5 comments
Closed

Which method is use to send messages? #38

Ham3D opened this issue Sep 19, 2015 · 5 comments

Comments

@Ham3D
Copy link

Ham3D commented Sep 19, 2015

Hello
i recently had a bug , i suppose this sdk use Get method to send text messaged to telegram api, right ?
when i try to send a big message a message pops up about :
{"\r\n<title>414_Request-URI_Too_Large</title></head>\r\n<body_bgcolor":""white">\r\n

414 Request-URI Too Large</h1></center>\r\n
nginx/1.6.2</center>\r\n</body>\r\n</html>\r\n"}
is there a way to use Post instead of Get ?

@jonnywilliamson
Copy link
Contributor

Good point. I wondered about this a few months ago.

@irazasyed - any reason why we use GET requests instead of POST requests when connecting to the telegram server?

I had a look and try to change the normal GET to POST in the code, but I wasn't sure how to set the parameters to application/x-www-form-urlencoded so I wasn't successful.

@jonnywilliamson
Copy link
Contributor

Actually I just worked it out.

If we change the $this->get to a $this->post in any of the send methods on the API, we have to add a form_params to the parameters.

This could be refactored, but a quick hack at the moment would look like this:

// Api.php

    /**
     * Send text messages.
     *
     * @link https://core.telegram.org/bots/api#sendmessage
     *
     * @param int    $chat_id
     * @param string $text
     * @param bool   $disable_web_page_preview
     * @param int    $reply_to_message_id
     * @param string $reply_markup
     *
     * @return Message
     */
    public function sendMessage(
        $chat_id,
        $text,
        $disable_web_page_preview = false,
        $reply_to_message_id = null,
        $reply_markup = null
    ) {
        $params = compact('chat_id', 'text', 'disable_web_page_preview', 'reply_to_message_id', 'reply_markup');
        $response = $this->post('sendMessage', ['form_params' => $params]);

        return new Message($response->getDecodedBody());
    }

@Ham3D
Copy link
Author

Ham3D commented Sep 21, 2015

it seems working , send a Pr

@irazasyed
Copy link
Owner

Please open a new PR and I can merge it. I won't be able to work on this until this month end. So either someone send a PR or please wait. Thanks!!

@jonnywilliamson
Copy link
Contributor

#40 Refers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants