0

as the title suggests, I'm having a problem with my Telegram bot. First a few things I want to clarify before i explain my problem. The Bot used to work earlier, received its updates, processed them and sent back a message with the calculated content.

I stopped working on it for a while, and when i worked with it again i got just no response at all. So i tried sending back the complete request to the private channel with my account, which worked. Unfortunately, the request was just empty, no content at all. When i tried to call the Webhook URL manually with some parameters (e.g. ..index.php?hi=owjal&lol=19) they did show up in the request.

What may be of interest is that i'm using the google app engine for my bot, there might be an issue i don't know about. I also noticed when the Bot receives a request from the Telegram-Servers, the php function ip2long returns an incorrect result, for the IP 149.154.167.204 it should return 2509940684, but i got -1785026612 instead, which also(?) turns to 149.154.167.204 . Here some of the code receiving the request sent by Telegram:

index.php

<?php
/**
* @author Tobias Franz
* 07.10.201616:52
*/
include "inc/config.dist.php";
$sender = '';
$sender = $_SERVER['REMOTE_ADDR'];
$senderIP = ip2long($sender);
file_get_contents(API_URL . "sendmessage?chat_id=<myChatId>&text=" . json_encode($_REQUEST).'IP:'.$senderIP);
/* Check if the message is sent by Telegram-Servers */
if ($senderIP <= 2509940713 && $senderIP >= 2509940677) {

I hope you can help me with this issue.

Tobias

Tobias F.
  • 1,050
  • 1
  • 11
  • 23
  • Why you are need to check sender? According documentation about Telegram's webhook: If you'd like to make sure that the Webhook request comes from Telegram, we recommend using a secret path in the URL, e.g. https://www.example.com/. Since nobody else knows your bot‘s token, you can be pretty sure it’s us. – Danil Pyatnitsev Feb 14 '17 at 01:50
  • Thanks for your advice @Danil . But my main Problem is that the Request sent by Telegram is just empty, e.g. no Content in GET, POST. – Tobias F. Feb 14 '17 at 05:53
  • 4
    ah... for getting requests data please use `$data = file_get_contents('php://input');` – Danil Pyatnitsev Feb 14 '17 at 05:55
  • Oh...I should've tried that, thank you, what a silly Mistake. I'll change it as soon as possible, i will tell ypu when it worked :-) – Tobias F. Feb 14 '17 at 05:57
  • Works now again, thanks for your help! – Tobias F. Feb 20 '17 at 06:37

0 Answers0