How to use the telegraf.Extra.inReplyTo function in telegraf

To help you get started, we’ve selected a few telegraf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github KrauseFx / FxLifeSheet / worker.ts View on Github external
// user entered a command to start the survey
    let command = ctx.match[1];
    let matchingCommandObject = config.userConfig[command];

    if (matchingCommandObject && matchingCommandObject.questions) {
      console.log("User wants to run:");
      console.log(matchingCommandObject);
      saveLastRun(command);
      if (
        currentlyAskedQuestionQueue.length > 0 &&
        currentlyAskedQuestionMessageId
      ) {
        // Happens when the user triggers another survey, without having completed the first one yet
        ctx.reply(
          "^ Okay, but please answer my previous question also, thanks ^",
          Extra.inReplyTo(currentlyAskedQuestionMessageId)
        );
      }

      currentlyAskedQuestionQueue = currentlyAskedQuestionQueue.concat(
        matchingCommandObject.questions.slice(0)
      ); // slice is a poor human's .clone basically

      if (currentlyAskedQuestionObject == null) {
        triggerNextQuestionFromQueue(ctx);
      }
    } else {
      ctx
        .reply("Sorry, I don't know how to run `/" + command)
        .then(({ message_id }) => {
          sendAvailableCommands(ctx);
        });
github telegram-ru / ru-bot / src / features / get-id / index.js View on Github external
async function onIdCommand({ reply, chat, from, message }) {
  debug('on !id', chat)
  try {
    return await reply(`Chat: ${chat.id}\nUser: ${from.id}`, Extra.inReplyTo(message.message_id))
  }
  catch (error) {
    // Message dropped?
    Sentry.captureException(error)
    return undefined
  }
}
github telegram-ru / ru-bot / src / features / spam-hammer / index.js View on Github external
moder: from,
        reason,
      }, keyboardUnspamUser({ banned: spammer }).extra())
      /** @see https://core.telegram.org/bots/api#forwardmessage */

      // TODO: search all entities in message (urls)
    }
    catch (error) {
      Sentry.captureException(error)
      debug('handleSpamCommand ERROR', error)
    }
  }
  else {
    reply(
      text.common.commandShouldBeReplied(text.commands.spam()),
      Extra.inReplyTo(message.message_id)
    )
  }
}
/* eslint-enable no-restricted-syntax */
github KrauseFx / FxLifeSheet / worker.ts View on Github external
let parsedUserValue = null;

  if (currentlyAskedQuestionObject.type != "text") {
    // First, see if it starts with emoji number, for which we have to do custom
    // parsing instead
    if (
      currentlyAskedQuestionObject.type == "range" ||
      currentlyAskedQuestionObject.type == "boolean"
    ) {
      let tryToParseNumber = parseInt(userValue[0]);
      if (!isNaN(tryToParseNumber)) {
        parsedUserValue = tryToParseNumber;
      } else {
        ctx.reply(
          "Sorry, looks like your input is invalid, please enter a valid number from the selection",
          Extra.inReplyTo(ctx.update.message.message_id)
        );
      }
    }

    if (parsedUserValue == null) {
      // parse the int/float, support both ints and floats
      userValue = userValue.match(/^(\d+(\.\d+)?)$/);
      if (userValue == null) {
        ctx.reply(
          "Sorry, looks like you entered an invalid number, please try again",
          Extra.inReplyTo(ctx.update.message.message_id)
        );
        return;
      }
      parsedUserValue = userValue[1];
    }
github KrauseFx / FxLifeSheet / worker.ts View on Github external
bot.on(["voice", "video_note"], ctx => {
    if (ctx.update.message.from.username != process.env.TELEGRAM_USER_ID) {
      return;
    }
    let message = ctx.message || ctx.update.channel_post;
    let voice =
      message.voice || message.document || message.audio || message.video_note;
    let fileId = voice.file_id;
    let transcribingMessageId = null;

    console.log("Received voice with file ID '" + fileId + "'");
    ctx
      .reply(
        "🦄 Received message, transcribing now...",
        Extra.inReplyTo(ctx.message.message_id)
      )
      .then(({ message_id }) => {
        transcribingMessageId = message_id;
      });

    let transcribeURL = "https://bubbles-transcribe.herokuapp.com/transcribe";
    transcribeURL += "?file_id=" + fileId;
    transcribeURL += "&language=en-US";
    transcribeURL += "&telegram_token=" + process.env.TELEGRAM_BOT_TOKEN;

    needle.get(transcribeURL, function(error, response, body) {
      if (error) {
        console.error(error);
        ctx.reply("Error: " + error, Extra.inReplyTo(ctx.message.message_id));
      }
      let text = JSON.parse(body)["text"];
github telegram-ru / ru-bot / src / middlewares / admin-required.js View on Github external
const adminRequired = async ({
  message, reply, chat, getChat, from,
}, next) => {
  if (chat && chat.type !== 'private') {
    const chatApi = getChat(chat.id)

    if (await chatApi.isAdmin(from)) {
      return next()
    }

    debug('Access denied', message, chat, from)
    return reply(text.notif.adminOnly(), Extra.inReplyTo(message.message_id))
  }

  return reply(text.notif.groupOnly(), Extra.inReplyTo(message.message_id))
}