Skip to content
This repository has been archived by the owner on Dec 6, 2018. It is now read-only.

How to POST a message? #1

Closed
DerekTso opened this issue Apr 20, 2018 · 7 comments
Closed

How to POST a message? #1

DerekTso opened this issue Apr 20, 2018 · 7 comments

Comments

@DerekTso
Copy link

HI,

I use tampermonkey to test the POST method, it returns {"result":"消息已经安排发送"}, but I didn't receive any message on tg.

var text = "test POST method";
GM_xmlhttpRequest({
    method: 'POST',
    headers: {
        "content-type": "application/x-www-form-urlencoded",
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
    },
    url: "https://tgbot.lbyczf.com/sendMessage/xxx",
    data: {
        "text": text,
        "parse_mode": "Markdown",
        "disable_web_page_preview": false
    },
    onload: (response) => {
        if (response.status >= 200 && response.status < 400) {
            console.info(response.responseText);
        }
    }
});```

//GET method works.
@Fndroid
Copy link
Owner

Fndroid commented Apr 20, 2018

try

data: 'text=' + encodeURIComponent(text) + '&parse_mode=Markdown&disable_web_page_preview=false',

"content-type": "application/x-www-form-urlencoded" tells the server to encode request body from a query string.

@DerekTso
Copy link
Author

DerekTso commented Apr 20, 2018

{"result":"消息已经安排发送","content":"![](http://xxx.com/test.jpg)"}

The text was sent, but [] was deleted, it shows on tg as !(http://xxx.com/test.jpg) instead.

seems it didn't support Markdown image.

"tg_push_bot" will enable image display in the future?

var text = "![](http://xxx.com/test.jpg)";
GM_xmlhttpRequest({
    method: 'POST',
    headers: {
        "content-type": "application/x-www-form-urlencoded",
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
    },
    url: `https://tgbot.lbyczf.com/sendMessage/xxx`,
    data: 'text=' + encodeURIComponent(text) + '&parse_mode=Markdown&disable_web_page_preview=false',
    onload: (response) => {
        if (response.status >= 200 && response.status < 400) {
            console.info(response.responseText);
        }
    }
});

@Fndroid
Copy link
Owner

Fndroid commented Apr 20, 2018

Already supported for sending photo with its URL.
The key of data is photo.

@DerekTso
Copy link
Author

failed again, nothing on tg and it returns as below.

{"result":"消息已经安排发送","content":"test","photo":"http://www.xxx.com/test.jpg"}

var url = encodeURIComponent("http://www.xxx.com/test.jpg");
GM_xmlhttpRequest({
    method: 'POST',
    headers: {
        "content-type": "application/x-www-form-urlencoded"
    },
    url: `https://tgbot.lbyczf.com/sendMessage/xxx`,
    data: 'text=test&photo=' + url,
    onload: (response) => {
        if (response.status >= 200 && response.status < 400) {
            console.info(response.responseText);
        }
    }
});

@Fndroid
Copy link
Owner

Fndroid commented Apr 20, 2018

@DerekTso Try encodeURI?

@DerekTso
Copy link
Author

still not good. (encodeURIComponent / encodeURI / or no encoding)

any successful example to POST a photo to tg? except on tampermonkey. not sure if it's tampermonkey issue

@Fndroid
Copy link
Owner

Fndroid commented Apr 20, 2018

@DerekTso Contact me on Telegram https://t.me/Fndroid

@Fndroid Fndroid closed this as completed Apr 21, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants