README ¶
Sequential Telegram Bot Workflow
Step 1
User initiates a Telegram Bot Command. e.g. /subscribe
Telegram App | Code Snippet |
|
|
Step 2
Request user for some more text input
Telegram App | Code Snippet |
|
|
Step 3
Request user input with custom Keyboard
Telegram App | Code Snippet |
|
|
Step 4
Request user confirmation using a custom keyboard and custom Reply Text Function
Telegram App | Code Snippet |
|
|
Step 5
Complete the workflow and return with the last step
Telegram App | Code Snippet |
|
|
Chaining the steps together
// Sequential Workflow. Chaining the steps.
step1.Next = &step2
step2.Next = &step3
step3.Next = &step4
step4.Next = &step5
Creating the Workflow and Workflow Controller
// Create a new workflow for command "/subscribe" with Step1 as at the root/starting step.
wf := tbotworkflow.NewWorkflow("WF1", "subscribe", &step1)
// Cancel button config for the entire workflow.
cancelBtnConfig := tbotworkflow.NewCancelButtonConfig("Cancel", "Canceling registeration.")
wf.CancelButtonConfig = cancelBtnConfig
// Create new Workflow Controller
wfc := tbotworkflow.NewWorkflowController("WFC")
// Add the Workflow to the controller. Any number of workflows can be added to a Workflow Controller.
wfc.AddWorkflow(&wf)
Executing the Workflow and processing the user inputs
// Process the Telegram Bot Updates
for update := range updates {
// Do any pre-processing before invoking the workflows here.
// Execute the workflow
userInputs, done := wfc.Execute(update.Message, botAPI.Send)
if !done {
continue
}
log.Printf("UserID: %d, Command: %s, Data: %v", userInputs.UID, userInputs.Command, userInputs.Data)
// Handle the user inputs as required.
}
2022/06/09 20:28:09 UserID: xxxxxxxx, Command: SUBSCRIBE, Data: map[Confirmation:Proceed Email:Hbb@hbb.com Name:HBB HBB Plan:Gold]
Documentation ¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.