hosein2398 / node-telegram-bot-api-tutorial Goto Github PK
View Code? Open in Web Editor NEWnode-telegram-bot-api tutorial
node-telegram-bot-api tutorial
Shortly:
Is it possible to move bot.onText
and others bot.on
event listeners to another JS file? Making some structure, when few related commands(even listeners) will be placed in one file, and another few - in another file, and finally include these commands into main script where bot initialized with something like mybot.useCommands(ModuleWithCommands1, Module2, Module3)
?
Full question is on StackOverflow: https://stackoverflow.com/questions/64318854/how-to-split-long-list-of-commands-to-different-files
I'm following your tutorial but I can't create keyboards, however I can see them in other bots (eg. TriviaBot). This is the code (copied from you tutorial), I have no idea what is wrong. When I send "/star" I only see "welcome".
const TelegramBot = require('node-telegram-bot-api');
const token = 'XXX:XXXXX';
const bot = new TelegramBot(token, {polling: true});
bot.onText(//start/, (msg) => {
bot.sendMessage(msg.chat.id, "Welcome", {
"reply_markup": {
"keyboard": [["Sample text", "Second sample"], ["Keyboard"], ["I'm robot"]]
}
});
});
Thank you so much for your help.
how can I reply with the web app button of the bot?
const results = JSON.stringify([
{
type: "article",
id: "1",
title: "Echo: " + queryText,
input_message_content: {
message_text: "You said: " + queryText,
},
},
]);
/* something like this????
const results = JSON.stringify([
{
type: "article",
id: "1",
title: "Echo: " + queryText,
input_message_content: {
message_text: "You said: " + queryText,
},
reply_markup: {
inline_keyboard: [
[
{
text: "Open Web App",
web_app: { url: "https://testbot.github.io/TONBot?id=32" }, // Web App URL
},
],
],
},
},
]);
*/
try {
/* await sendMessageWithWebAppButton(
chatId, // you don't have chatID on inline only on message
"Open Web App using the button below:",
"https://testbot.github.io/TONBot?id=32",
); */
await fetch(
`${telegramApi}/answerInlineQuery?inline_query_id=${queryId}&results=${results}`,
);
res.sendStatus(200);
}
Hi,
Im writing a code in node js, using the "node-telegram-bot-api" library version"^0.64.0".
Im using the sendPhoto method... to send a photo... and in the caption im trying to do some formatting.
I am able to do bold, but im not able to do strike.
I have tried parse_mode = MarkdownV2, but it breaks.
I have also tried using a single and double ~ character.
let message = "*bold text*\n\n~strike~\n\n~~Striked~~";
const imgStream = request.get(imageUrl).on('error', function(err) { console.log(err); });
bot.sendPhoto(process.env.telegram_group_id, imgStream, { parse_mode: 'Markdown', caption: message, })
.then(() => {
console.log('Message sent successfully');
})
.catch((error) => {
console.error('Error sending message: ', error);
});
}
Any ideas?
Thanks
I wonder what is the role of the polling argument.
Hi, guys.
I created a 'bot' in Telegram and added it to the group as an admin.
Today I read the documentation and only teaches how to interact with the bot in the 'Interacting with groups and channels' section. Need to make the bot send message to the group even without user interaction.
Can anybody help me?
How do I compile a deleteMessage?
Please teach me how to compose this deleteMessage ,Thanks
my email: [email protected]
Hi,
My bot does work on bot chat when we send message to it perfectly, but here is the issue:
When I send message in my channel (which my bot also is admin of that channel) I receive this error
error: [polling_error] {"code":"ETELEGRAM","message":"ETELEGRAM: 409 Conflict: terminated by other getUpdates request; make sure that only one bot instance is running"}
What I'm trying to do is:
When new user join to the channel my bot send message into channel such as
Welcome to {channel_name} channel {user_name}
How can I do that?
hi guys i was trying to create a telegram bot that sends a location after receiving some texts, but when ever i tried to send my location(using telegram location button to send location) it keeps throwing polling error please i need help am on a deadline error: [polling_error] {}
here is my code
bot.on("location",(msg)=>{
bot.sendMessage(msg.chat.id, "We will deliver your order to " + [msg.location.longitude,msg.location.latitude].join(";"));
});
here is the full code
bot.onText(//start/, (msg) => {
bot.sendMessage(msg.chat.id, "welcome to app name"){
"reply_markup": {
"keyboard": ["Arada", "Gullele"]
}
});
});
bot.on('message', (msg) => {
var feelings = [
"Arada", "Gullele"
];
if (msg.text.indexOf(feelings[0]) === 0) {
bot.sendMessage(msg.chat.id, "Your data is registered");
}
else if (msg.text.indexOf(feelings[1]) === 0) {
bot.sendMessage(msg.chat.id, "Your data is not registered");
}
// I THINK THE PROBLEM IS HERE
bot.on("location",(msg)=>{
bot.sendMessage(msg.chat.id, "We will deliver your order to " + [msg.location.longitude,msg.location.latitude].join(";"));
});
Hello and thank you for you amazing work. I love this repo: it allowed me, even if I was new to NodeJS, to create a Telegram Bot that I successfully deployed on Firebase.
I soon realized though that, after some time the bot doesn't get HTTP requests, it stops working for good, until I re-deploy it. Googling around, I came to the conclusion that it's a matter of Firebase token refreshing. Nonetheless, I can't find a way to make the bot successfully refresh it, since all the documentation I can find refers on website's user logins IDs...
Can someone help me figuring out some JS code to keep my bot running even after Firebase catalogs my current token as expired?
I'm using the JSON form '**.key' file Firebase provides me here
Thank you so much
I think beginners would appreciate if examples on webhooks were included.
Hi, how to use or call the getMe
method? I didn't know how to add more of the Promise<TelegramBot.User>
parameters,
I've tried to use it like:
console.log(bot.getMe());
the result was like this:
<ref *1> Promise [Object] {
_bitField: 0,
_fulfillmentHandler0: undefined,
_rejectionHandler0: undefined,
_promise0: undefined,
_receiver0: undefined,
_cancellationParent: <ref *2> Promise [Object] {
_bitField: 1,
_fulfillmentHandler0: undefined,
_rejectionHandler0: [Function (anonymous)],
_promise0: [Circular *1],
_receiver0: undefined,
_cancellationParent: Promise [Object] {
_bitField: 1,
_fulfillmentHandler0: [Function (anonymous)],
_rejectionHandler0: undefined,
_promise0: [Circular *2],
_receiver0: undefined,
_onCancelField: [Function (anonymous)],
_branchesRemainingToCancel: 1
},
_branchesRemainingToCancel: 1
}
}
Thank you for any reply.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.