【问题标题】:Telegram Bot sendDocument problem with filenameTelegram Bot sendDocument 文件名问题
【发布时间】:2021-09-12 10:19:46
【问题描述】:

我尝试像这样发送 .pdf 文件:

await bot.sendDocument(chatId, fs.readFileSync(outputFilePath), {}, {
    filename: outputFileName,
    contentType: 'application/pdf',
})

但如果文件名至少包含这些字符“§¤&`£€'”中的一个,则所有此类字符都将被过滤掉。

此外,这些字符对于文件本身的名称也是有效的。

研究问题,我得出的结论是我需要使用'percent-encoding',但是我该如何使用'sendDocument'方法呢?

【问题讨论】:

    标签: javascript node.js pdf telegram-bot node-telegram-bot-api


    【解决方案1】:

    试试:

    const caption = { caption: "caption" ?? path.basename(outputFilePath) };
    const file = { filename: path.basename(outputFilePath), source: await fs.createStream(outputFilePath)};
    
    await bot.telegram.sendDocument(chatId, file, caption);
    

    【讨论】:

      猜你喜欢
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 2021-05-20
      • 2021-04-11
      • 2016-02-29
      • 2021-10-03
      • 1970-01-01
      • 2018-10-09
      相关资源
      最近更新 更多