-
Notifications
You must be signed in to change notification settings - Fork 2
Message Context
Alper Kürşat edited this page Feb 14, 2022
·
1 revision
Contexts are simple Turing Machines that manages consecutive sends.
Whenever send forward reply and copy method called, a new message context created and attached as related key. (.send() -> .sent)
| Method | Created Context |
|---|---|
| reply() | .replied |
| send() | .sent |
| forward() | .forwarded |
| copy() | .copied |
| delete() | No |
Let's assume that we have an incoming message(A), if we call res.reply(), we send a reply to A. This creates a new context at .replied (B).
If we call .reply again (res.reply().reply()) we reply to the original message(A) again.
But if we call .reply to the .replied (res.reply().replied.reply()), we reply to our own message(B).
| Example Code | Context |
|---|---|
| res | A |
| res.reply() | A |
| res.reply().reply() | A |
| res.reply().replied | A:B |
| res.reply(). |
Error |
| res.reply().forward().forwarded | A:C |
| res.reply().replied.forward().forwarded | A:D:E |

No matter you write chained methods, Botocrat handles async part and waits for the sent message before sending a new message in created context.
As diagram shows above, you can get the sent message via .then method.
...
res.reply("This is a reply")
.replied.then((reply) => {
console.log(reply.text) // "This is a reply"
})
...