Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js Nodejs电报机器人:等待网络呼叫时发送ChatAction_Node.js_Telegram Bot_Telegraf - Fatal编程技术网

Node.js Nodejs电报机器人:等待网络呼叫时发送ChatAction

Node.js Nodejs电报机器人:等待网络呼叫时发送ChatAction,node.js,telegram-bot,telegraf,Node.js,Telegram Bot,Telegraf,我正在Nodejs中使用Telegraf框架编写一个电报机器人,并希望在机器人执行网络呼叫时显示“机器人正在键入…”横幅 我遇到的问题是,我的函数没有按预期的方式执行,即“键入”横幅在5秒后出现并消失(根据文档),但发票直到至少30秒后才会发送。评估日志还表明,控制台日志是在函数结束后执行的 以下是我的实现: module.exports = (bot) => bot.command('buy', (ctx) => { let catalogueId = //some reg

我正在Nodejs中使用Telegraf框架编写一个电报机器人,并希望在机器人执行网络呼叫时显示“机器人正在键入…”横幅

我遇到的问题是,我的函数没有按预期的方式执行,即“键入”横幅在5秒后出现并消失(根据文档),但发票直到至少30秒后才会发送。评估日志还表明,控制台日志是在函数结束后执行的

以下是我的实现:

module.exports = (bot) => bot.command('buy', (ctx) => {
    let catalogueId = //some regex 
    return Promise.all([
        ctx.replyWithChatAction('typing'),
        sendInvoice(catalogueId, ctx)
    ]) 
})

function sendInvoice(catalogueId, ctx) {
    console.log('1')
    return helper.getItem(catalogueId)
    .then((item) => {
        console.log('2')
        return createInvoice(item, ctx)
        .then((invoice) => {
            console.log('3')
            return ctx.replyWithInvoice(invoice)
        })
    })
}
在我的Firebase云函数中看到的日志语句如下所示:

如您所见,控制台日志是在函数结束后打印的,并且相隔大约15秒。其他尝试:

//Attempt 2, same result as above
module.exports = (bot) => bot.command('buy', (ctx) => {
    let catalogueId = //some regex 
    return ctx.replyWithChatAction('typing')
    .then(() => sendInvoice(catalogueId, ctx))
})

//Attempt 3, log statements are printed before function ends, but the 'typing' only shows at the end. Need it to show when the networking calls starts
module.exports = (bot) => bot.command('buy', (ctx) => {
    let catalogueId = //some regex 
    return sendInvoice(catalogueId, ctx))
})

function sendInvoice(catalogueId, ctx) {
    console.log('1')
    return helper.getItem(catalogueId)
    .then((item) => {
        console.log('2')
        return createInvoice(item, ctx)
        .then((invoice) => {
            console.log('3')
            return ctx.replyWithChatAction('typing')
            .then(() => ctx.replyWithInvoice(invoice))
        })
    })
}

我的机器人目前部署在Firebase云功能上。

请不要在此处使用类似“pls”(意思是请)的缩写词。不管怎样,技术写作在这里是首选的,因为我们在这里发表文章是为了长期读者的利益。请注意,我们更喜欢技术风格的写作在这里。我们轻轻地劝阻问候,希望你能帮助,谢谢,提前感谢,感谢信,问候,亲切的问候,签名,请你能帮助,闲聊的材料和缩写的txtspk,恳求,你被困多久了,投票建议,元评论等。只需解释你的问题,并展示你已经尝试了什么,你期望什么,以及实际发生的事情。请不要在这里使用像“pls”(意思是请)这样的缩写词。不管怎样,技术写作在这里是首选的,因为我们在这里发表文章是为了长期读者的利益。请注意,我们更喜欢技术风格的写作在这里。我们轻轻地劝阻问候,希望你能帮助,谢谢,提前感谢,感谢信,问候,亲切的问候,签名,请你能帮助,闲聊的材料和缩写的txtspk,恳求,你被困多久了,投票建议,元评论等。只需解释你的问题,并展示你已经尝试了什么,你期望什么,实际上发生了什么。