Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const hitQuestionButton = async ctx => {
const extra = Extra.markup(Markup.forceReply())
await Promise.all([
ctx.reply(questionText, extra),
ctx.answerCbQuery(),
ctx.deleteMessage()
.catch(error => {
if (/can't be deleted/.test(error)) {
// Looks like message is to old to be deleted
return
}
console.error('deleteMessage on question button failed', error)
})
])
}
function triggerNextQuestionFromQueue(ctx) {
let keyboard = Extra.markup(m => m.removeKeyboard()); // default keyboard
let questionAppendix = "";
currentlyAskedQuestionObject = currentlyAskedQuestionQueue.shift();
if (currentlyAskedQuestionObject == null) {
ctx.reply("All done for now, let's do this 💪", keyboard);
// Finished
return;
}
if (currentlyAskedQuestionObject.question == null) {
console.error("No text defined for");
console.error(currentlyAskedQuestionObject);
}
if (currentlyAskedQuestionObject.type == "header") {
[getButtonText("0")]
];
shuffleArray(allButtons);
keyboard = Markup.keyboard(allButtons)
.oneTime()
.extra();
} else if (currentlyAskedQuestionObject.type == "boolean") {
keyboard = Markup.keyboard([["1: Yes"], ["0: No"]])
.oneTime()
.extra();
} else if (currentlyAskedQuestionObject.type == "text") {
// use the default keyboard we set here anyway
questionAppendix +=
"You can use a Bear note, and then paste the deep link to the note here";
} else if (currentlyAskedQuestionObject.type == "location") {
keyboard = Extra.markup(markup => {
return markup.keyboard([
markup.locationRequestButton("📡 Send location")
]);
});
}
questionAppendix = currentlyAskedQuestionQueue.length + " more question";
if (currentlyAskedQuestionQueue.length != 1) {
questionAppendix += "s";
}
if (currentlyAskedQuestionQueue.length == 0) {
questionAppendix = "last question";
}
let question =
currentlyAskedQuestionObject.question + " (" + questionAppendix + ")";
function getKeyboardExtra (url: string, refresh?: RefreshData) {
return Extra.markup(() => getButtons(url, refresh))
}
selectLanguage(ctx, isStart) {
const lang = ctx.state.userSettings.language;
const message = L(lang, 'ASK_CHANGE_LANGUAGE');
return ctx.reply(message, Extra.markup(
Markup.inlineKeyboard([
Markup.callbackButton('English', 'setlang|en|' + (isStart ? '1' : '0')),
Markup.callbackButton('Русский', 'setlang|ru|' + (isStart ? '1' : '0'))
])
));
},
changeLanguage(ctx, language) {
this.bot.action(actionCode, this.hideMiddleware(hide, ctx => {
const extra = Extra.markup(Markup.forceReply())
return Promise.all([
ctx.reply(questionText, extra),
ctx.deleteMessage()
])
}))
sendVideoUrl(userId, chatId, videoId, message, lang) {
let msg = (message ? `${message} ` : '');
msg += `https://www.youtube.com/watch?v=${videoId}`;
return this._bot.telegrafApp.telegram.sendMessage(chatId, msg, Extra.markup(
Markup.inlineKeyboard([
Markup.callbackButton(L(lang, 'REMIND'), `remind|${videoId}`)
])
));
},
showRemindButton(ctx) {
p = p.then(() => {
return ctx.reply(message, Extra.markup(
Markup.inlineKeyboard([
Markup.callbackButton(L(lang, 'DO_NOT_REMIND_ME'), `removeRemind|${videoId}`)
])
))
})
});