Closed AdelaFoofur82 closed 2 years ago
Trying to pass the parameters in JSON.stringify() format does not recognize it either, although the server returns true
I tried restarting the client to see if the changes were made with no results.
I will assume that the method works as it should, but you do not have users for whom you specify language_code or scope is not suitable for the group Try to change these parameters so that they satisfy the group and the user through whom you check the changes It is also important to switch to a third-party chat and come back, only in this case the changes will take effect
I don't know how but it was solved
I tried setting the commands via BotFather, I don't know if this is what fixed the problem.
@gladunvv The scope object need to parse a JSON.stringify()
. We can do it internal in the library the fix and you don't need to put it the stringify. Fix in the next release
I believe the scope part of the setMyCommands and getMyCommands is also broken. The GetMyCommands call doesn't send the scope at all
+1
+1
+1 same problem
I tried just now, working for me. ( setMyCommands
with node-fetch
)
I tried just now, working for me. (
setMyCommands
withnode-fetch
)
Could you please share the payload for setMyCommands request?
Could you please share the payload for setMyCommands request?
Sure try this;
const telegramBot = require('node-telegram-bot-api');
const token = "BOT_TOKEN"
const bot = new telegramBot(token, { polling: true });
const fetch = require('node-fetch');
bot.request = async function (command, json) {
return fetch(`https://api.telegram.org/bot${token}/${command}`, {
method: 'post',
body: JSON.stringify(json),
headers: { 'Content-Type': 'application/json' }
});
}
bot.request('setMyCommands', {
commands: [
{
command: "Command 1",
description: "Command 1 Description."
},
{
command: "Command 2",
description: "Command 2 Description."
}
],
scope: {"type": "all_private_chats"}, // This is adding commands for Private Message with Bot. Find Scopes on API.
language_code: "en" // Language; en = English.
});
Edit: If you don't see commands wait a bit, or select other chat and back to chat with bot.
Oh also you don't need to add slash ( / ) inside command string.
bot.request = async function (command, json) {
return fetch(`https://api.telegram.org/bot${token}/${command}`, {
method: 'post',
body: JSON.stringify(json),
headers: { 'Content-Type': 'application/json' }
});
}
bot.request('setMyCommands', {
commands: [
{
command: "Command 1",
description: "Command 1 Description."
},
{
command: "Command 2",
description: "Command 2 Description."
}
],
scope: {"type": "all_private_chats"}, // This is adding commands for Private Message with Bot. Find Scopes on API.
language_code: "en" // Language; en = English.
}).then(r => console.log(r));
[Symbol(realm)]: null,
[Symbol(state)]: {
aborted: false,
rangeRequested: false,
timingAllowPassed: true,
requestIncludesCredentials: true,
type: 'default',
status: 400,
timingInfo: {
startTime: 333.6870999969542,
redirectStartTime: 0,
redirectEndTime: 0,
postRedirectStartTime: 333.6870999969542,
finalServiceWorkerStartTime: 0,
finalNetworkResponseStartTime: 0,
finalNetworkRequestStartTime: 0,
endTime: 0,
encodedBodySize: 78,
decodedBodySize: 78,
finalConnectionTimingInfo: null
},
cacheState: '',
statusText: 'Bad Request',
headersList: HeadersList {
[Symbol(headers map)]: [Map],
[Symbol(headers map sorted)]: null
},
urlList: [ [URL] ],
body: { stream: undefined }
},
'connection' => 'keep-alive',
'strict-transport-security' => 'max-age=31536000; includeSubDomains; preload',
'access-control-allow-origin' => '*',
'access-control-expose-headers' => 'Content-Length,Content-Type,Date,Server,Connection'
},
[Symbol(headers map sorted)]: null
}
}```
I'm sending this for who doesn't understand;
( P.S: If node-fetch
not work, try with 2.6.7
version. You can install with; npm install node-fetch@2.6.7
, but don't forget uninstall previous version with; npm uninstall node-fetch
. )
Sorry for my poor English :)
const telegramBot = require('node-telegram-bot-api');
const token = "YOUR_BOT_TOKEN_HERE";
const bot = new telegramBot(token, { polling: true });
const fetch = require('node-fetch');
bot.request = async function (command, json) {
return fetch(`https://api.telegram.org/bot${token}/${command}`, {
method: 'post',
body: JSON.stringify(json),
headers: { 'Content-Type': 'application/json' }
});
}
bot.request('setMyCommands', {
commands: [
{
command: "start",
description: "This is start the game hehe..."
}
],
scope: {"type": "all_private_chats"},
language_code: "en"
}).then(r => console.log(r));
bot.onText(/\/start/, (msg) => {
bot.sendMessage(msg.chat.id, `Welcome.`, {
"reply_markup": {
"keyboard": [
["Sample text", "Second sample"]
]
}
});
});
anyone tried doing this in C#?
I'm doing what you guys are trying to do with java. I found this and it gives me like,
It doesn't even give me true or false. It's because it failed sending the SetMyCommands, obviously.
It seems that using 'https://api.telegram.org/bot${token}/setMyCommands' is the only way to achieve what we want. Isn't it?
I'm doing what you guys are trying to do with java. I found this and it gives me like,
It doesn't even give me true or false. It's because it failed sending the SetMyCommands, obviously.
It seems that using 'https://api.telegram.org/bot${token}/setMyCommands' is the only way to achieve what we want. Isn't it?
I use it with fetch (Node Fetch v2.6.7) using this url:
https://api.telegram.org/bot${token}/${command}
and set body with JSON strings, you can see my previous messages.
Expected Behavior
setMyCommands actual sets the commands of the bot
Actual Behavior
Not changes, but receiving a true
Steps to reproduce the Behavior
Using:
returns true, but no changes applied.
I guess it's the way is sending the info, because it uses internally
x-www-form-urlencoded
and sending it as JSON works:I think is the mix of sending the array of commands as a stringified JSON while sending everything else as
x-www-form-urlencoded
format.Maybe you should use JSON in the entire library? It seems to be the native way of Telegram API to work.