skip to Main Content

I don’t know how to send data through variable on this code

<?php
require 'vendor/autoload.php';
use TelegramBotApi;
$telegram = new Api('376072170:AAE2_y5EpVRCwc8Xbe-GHJLNP9yUdP2Zzto');
$chatid=$_POST['id'];
$text=$_POST['msg'];
$response = $telegram->sendMessage([
  'chat_id' => 'chatid', 
  'text' => 'some text here'
]);
$messageId = $response->getMessageId();

I did something like this

<?php
require 'vendor/autoload.php';
use TelegramBotApi;
$telegram = new Api('376072170:AAE2_y5EpVRCwc8Xbe-GHJLNP9yUdP2Zzto');
$chatid=$_POST['id'];
$text=$_POST['msg'];
$response = $telegram->sendMessage([
  'chat_id' => $chatid, 
  'text' => $text
]);
$messageId = $response->getMessageId();

but all that I get is an error 500 on the browser what should I do to can get it to work
I wanna send data through a form but I don’t know what to do
thanks for your help

this is my heroku log

2017-03-26T13:19:25.215850+00:00 heroku[router]: at=info method=GET path=”/msg.php” host=telebotyx.herokuapp.com request_id=cc595063-19ca-48a2-9f19-5832d79d4603 fwd=”200.73.16.3″ dyno=web.1 connect=0ms service=1164ms status=500 bytes=169 protocol=https
2017-03-26T13:19:25.229754+00:00 app[web.1]: [26-Mar-2017 13:19:25 UTC] PHP Fatal error: Uncaught TelegramBotExceptionsTelegramOtherException: Bad Request: message text is empty in /app/vendor/irazasyed/telegram-bot-sdk/src/Exceptions/TelegramResponseException.php:58
2017-03-26T13:19:25.229763+00:00 app[web.1]: Stack trace:
2017-03-26T13:19:25.229821+00:00 app[web.1]: #0 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramResponse.php(174): TelegramBotExceptionsTelegramResponseException::create(Object(TelegramBotTelegramResponse))
2017-03-26T13:19:25.229931+00:00 app[web.1]: #1 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramResponse.php(204): TelegramBotTelegramResponse->makeException()
2017-03-26T13:19:25.230043+00:00 app[web.1]: #2 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramResponse.php(65): TelegramBotTelegramResponse->decodeBody()
2017-03-26T13:19:25.230206+00:00 app[web.1]: #3 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramClient.php(138): TelegramBotTelegramResponse->__construct(Object(TelegramBotTelegramRequest), Object(GuzzleHttpPsr7Response))
2017-03-26T13:19:25.230367+00:00 app[web.1]: #4 /app/vendor/irazasyed/telegram-bot-sdk/src/TelegramClient.php(119): TelegramBotTelegramClient->getResponse(Object(TelegramBotTelegramRequest), Object(GuzzleHttpPsr7Response))
2017-03-26T13:19:25.230513+00:00 app[web.1]: #5 /app/vendor/irazasyed/telegram-bot-sdk/src/Api.php in /app/vendor/irazasyed/telegram-bot-sdk/src/Exceptions/TelegramResponseException.php on line 58
2017-03-26T13:19:25.231648+00:00 app[web.1]: 10.179.109.26 – – [26/Mar/2017:13:19:24 +0000] “GET /msg.php HTTP/1.1” 500 – “-” “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36

2

Answers


  1. Looks like something is going wrong in your form. Since the error is “… Bad Request: message text is empty…”

    Check if your input field names are ‘id’ and ‘msg’.
    Also check if your form method is POST.

    Login or Signup to reply.
  2. You are not using POST to transmit your form.

    method=GET path=”/msg.php”

    Either switch to $_REQUEST or use POST in the HTML tag:

    <form action="/msg.php" method="post">
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search