Messengerボットを介して一連のメッセージをいくつか送信し、タイピング効果を表示したいとします。メッセンジャーでsetTimeoutとPromisesを正しく使用する方法
sendTextMessage(recipientId, `Howdy ${snapshot.child("userDetails/firstName").val()}! I’m Marco :)`)
sendSenderAction(recipientId, "typing_on")
setTimeout(()=>sendTextMessage(recipientId, "Botting Marco."),1000)
sendSenderAction(recipientId, "typing_on")
setTimeout(()=>sendTextMessage(recipientId, "Let me show you some of my recent work. This is the first portfolio bot ever. (afaik) :p"),5000)
sendSenderAction(recipientId, "typing_on")
setTimeout(()=>sendTextMessage(recipientId, "How many minutes do you have?"),7000)
userRef.update({stage:1, class:1, awaiting: true})
しかし、タイピングの効果は、いくつかの理由で表示されません。現在、私はこのコードを持っています。前回の処理が完了したときに各行が実行されるように私は約束を使用する必要がありますか?私に例を教えてもらえますか?
いいえ、あなたは約束を使用する必要はありません。どんな種類のコールバックメカニズムも同様に機能します。連鎖することができるため、「ピラミッド・オブ・ドゥーム」や「コールバック・ヘルあなたのコードで –