0

I try to use Telegram's getupdates URL to get updates from telegram. For example, the URL below shows the details of the last message

URL:
    https://api.telegram.org/bot<token>/getupdates?offset=-1
Response:
{"ok":true,"result":[{"update_id":22222222,
"channel_post":{"message_id":200,"sender_chat":{"id":-1000,"title":"Channel","username":"xxx","type":"channel"},"chat":{"id":-1000,"title":"xxx","username":"xxx","type":"channel"},"date":1111111,"text":"Hello world"}}]}

But, I want to receive only the "text" parameter as the response

    Hello world

So what strings should I add to the end of the url so that I can filter the text parameter in the server response?

starball
  • 20,030
  • 7
  • 43
  • 238
matin
  • 111
  • 10

1 Answers1

1

Unfortunately, this is not possible.

The getUpdates() route will always return an array of update objects, there's no way to change that for now.

You should write some custom code to reduce the objects to just the desired fields.


Based on OP's comment, the 'custom code' could look like this:

// Data from getUpdates, containing a single example message
const data = {
    "ok": true,
    "result": [
        {
            "update_id": 1234567,
            "message": {
                "message_id": 752,
                "from": { "id": 12122121, "is_bot": false, "first_name": "Me", "last_name": "&", "username": "&&&&", "language_code": "en" },
                "chat": { "id": -1041255, "title": "Some group", "type": "supergroup" },
                "date": 1579999999,
                "text": "Hi!"
            }
        }
    ]
};
// Get Message Text
const messageText = data.result[0].message.text;
console.log(messageText);
0stone0
  • 34,288
  • 4
  • 39
  • 64