Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Set default parse_mode? #2064

@mmkal

Description

@mmkal

Is your feature request related to a problem? Please describe.

Not a big problem, but I have a lot of lines looking like await ctx.sendMessage(message, {parse_mode: 'MarkdownV2'}) which feels a bit noisy, and it also requires being vigilant. My application uses markdown heavily and almost all user facing strings are assumed to be markdown. So as well as the repetition, there are cases where we forget to add the parse_mode and then things fail in unexpected ways.

Describe the solution you'd like

Something like

const bot = new Telegraf(process.env.BOT_TOKEN, {
  defaults: { parse_mode: 'MarkdownV2' },
)

Describe alternatives you've considered

  1. Manually typing parse_mode: 'MarkdownV2' for every message sent (current solution, but it's cumbersome and error-prone)
  2. Wrapping the ctx that's passed into the event handlers (not tried because there are many different ways to send a message - unsure how to wrap only the "base" sendMessage implementation, that's something that's correctly abstracted away)

Additional context

The above proposal suggests defaults so that other "extras" can have defaults, but since there are different contextual "extras", maybe it'd need to be divided up between the different types, if there is overlap or something.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions