1
votes

Hi what the problem with this JSON

{"chat_id":149003957,"text":"Please Select your Language","reply_markup":{"keyboard":[[{"text":"English"},{"text":"Deutsh"}],[{"text":"Français"},{"text":"PyccKNN"}],[{"text":"Italiano"},{"text":"Espagnol"}]]}}

it give HTTP 400 when passed as a post request to Telegram Bot API methond "sendMessage"

1
Hi, can you add the code where you make the request? Also, from the documentation, you should get a more descriptive error in the body of the 400 response. Can you share that as well? core.telegram.org/bots/api#making-requests - AnilRedshift
@AnilRedshift "ok": false, "error_code": 400, "description": "Bad Request: message text is empty" - Seif
It sounds like the text field is empty. Can you post the code that is making the request? - AnilRedshift
Hey, it is actually "Deutsch" you seem to have a little typo here. :) - creyD
@AnilRedshift thanks the json was correct , the code added extra bytes. - Seif

1 Answers

0
votes

i post your object to telegram bot API and successfully receive the message. nothing is wrong with your object. here is my sample code in c#:

private static T Call<T>(string body)
{
    var contentBytes = Encoding.UTF8.GetBytes(body);
    var request = (HttpWebRequest)WebRequest.Create("your bot url" + "methodName");

    request.Timeout = 60 * 1000;
    request.ContentLength = contentBytes.Length;
    request.Method = "POST";
    request.ContentType = @"application/json";

    using (var requestWritter = request.GetRequestStream())
        requestWritter.Write(contentBytes, 0, (int)request.ContentLength);

    var responseString = string.Empty;
    var webResponse = (HttpWebResponse)request.GetResponse();
    var responseStream = webResponse.GetResponseStream();
    using (var reader = new StreamReader(responseStream))
        responseString = reader.ReadToEnd();

    return JsonConvert.DeserializeObject<T>(responseString);
}

your message