Skip to content

silikidi/Telegram-JSON-Response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram JSON Response

JSON response samples for Telegram API developers. Based on Bot API 5.3. For details see the documentation.

Generator

Code.gs powered by Telegram Bot API v5.3 and Google Apps Script.

Each JSON response from the Telegram Bot API will be sent back by Google Apps Script as a message via Google web apps connected to the Telegram webhook. The results appear in the chat bot whenever a user submits certain content. You can change it to the Apps Script's Logger.log.

You can even more simplify the script with ES6 notation.

Media Group

The JSON's media group is sent separately for each object. If in one media group there is one video, two images, and a caption text, it will be sent in four JSON modules of text, video, and two photos with the same media_group_id.

Live Location

The JSON's Live Location will be sent according to the update range in live_period between every 60 and 86400 seconds with default every 900.

Poll Handling

The JSON response from a Poll can only be captured when the Poll is created by the user. The JSON response from the Poll answer itself cannot be captured, but instead sent to the user who created it.

The JSON response from Poll answer can only be captured if the Poll is created by the Bot with the sendPoll method. The JSON response from the Poll itself cannot be captured.

Example of the sendPoll method with options property in a Array of String of JSON-serialized list of answer 2-10 strings 1-100 characters each:


let now = new Date();
now.setHours( now.getHours() + 1 );

let dataPoll = {
  method: "post",
  payload: {
    method: "sendPoll",
    chat_id: String( chatid ),
    question: "Your favorite color",
    options: JSON.stringify( [ "RED", "GREEN", "BLUE" ] ),
    is_anonymous: "false",
    type: "quiz",
    allows_multiple_answers: "true",
    correct_option_id: "2",
    explanation: "Because <b>BLUE</b> is the color of <a href='https://telegram.org'>Telegram</a>.",
    explanation_parse_mode: "HTML",
    close_date: String( now.getTime() )
    
    //in case need more complicated...
    //close_date: String( Utilities.formatDate( now, Session.getScriptTimeZone(), "yyyy-MM-dd'T'HH:mm:ss'Z'" ) )
    
  }
};

UrlFetchApp.fetch( telegramAPIURL + "/", dataPoll );

//let response = UrlFetchApp.fetch( telegramAPIURL + "/", dataPoll );
//Logger.log( response.getContentText() );

Add poll commands with @BotFather to generate a test poll:

start - Command test
poll000 - Poll anonymous regular single answer
poll001 - Poll anonymous regular multiple answer
poll010 - Poll anonymous quiz single answer
poll011 - Poll anonymous quiz multiple answer
poll100 - Poll non anonymous regular single answer
poll101 - Poll non anonymous regular multiple answer
poll110 - Poll non anonymous quiz single answer
poll111 - Poll non anonymous quiz multiple answer

Quiz cannot be mixed with Multiple-answer. poll011 and poll111 command is used to see Telegram's priority over these two properties when both forced to combine.

Poll command

Poll Answer Handling

See POLL-JSON-Handler-Script.gs

Sample Bot

JSON Response Bot @simrsjsonbot powered by Code.gs

Screenshot

About

Example JSON Response from Telegram API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published