docs/

directory
v1.9.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 25, 2024 License: MIT

README ΒΆ

Documentation πŸ“š

Understanding the Flows

The flow defines the user's path through the bot. πŸ›£οΈ

It has steps that specify the details of each step.

Each step has mandatory values, and they are:

  • action: Defines the action taken.
  • parameters: Additional information about action.
  • next: Informs the next step.

The flow must be written in a YAML file, here is an example: πŸ‘‡πŸ»

name: flow

steps:
  mystep:
    # Send a text
    action: Text
    parameters:
      # Defines the text that will be send to the action Text
      texts:
        - Some text
    # Informs the next step, the value "default" is required
    next:
      default: nextstep

  nextstep: ...

Now let's understand about each of the values mentioned. 🀩

Actions and Parameters

The action are functions that contain business rules.

LowBot implements standard actions with common rules.

In addition to the business rule, each action needs to inform whether it should wait for an interaction from the user, or continue to the next step.

Each action has additional data that is entered in parameters.

Action Description Parameter Type Wait ?
Text Send texts texts []string ❌
Image Send image image string ❌
Video Send video video string ❌
Document Send document document string ❌
Input Send texts input string βœ…
Button Send texts and buttons buttons []string βœ…
Wait Only wait - - βœ…
Example Action Text
action: Text
parameters:
  texts:
    - "Hello"
    - "Welcome to LowBot"
Example Action Image
action: Image
parameters:
  # Image supports local path or url
  image: image.png | https://myimage.com/image.png
Example Action Video
action: Video
parameters:
  # Video supports local path or url
  video: video.mp4 | https://myvideo.com/video.mp4
Example Action Document
action: Document
parameters:
  # Document supports local path or url
  document: document.txt | https://mydoc.com/document.txt
Example Action Input
action: Input
parameters:
  texts:
    - "Hello"
    - "Are you fine?"
Example Action Button
action: Button
parameters:
  texts:
    - "Hello"
    - "Are you fine?"
  buttons:
    - Yes
    - No
Example Action Wait
action: Wait

Action Function

Now that we understand that the action is a function, and that we need to tell the step which action will be performed, let's understand better its signature.

func (flow *Flow, channel Channel) (bool, error) {}

The action function receive two parameters:

  • flow: Flow pointer.
  • channel: Communication Channel.

The function should return two values:

  • bool: Indicates whether the flow should wait to the next step or proceed.
  • error: Indicates if an error occurred when executing the action.

Custom Actions

If you need custom actions, you can create and define them with the SetCustomActions function.

myActions := lowbot.ActionsMap{
    "Custom": func(flow *lowbot.Flow, channel lowbot.IChannel) (bool, error) {
        // your rules
        wait := true
        return wait, nil
    },
}

lowbot.SetCustomActions(myActions)

The definition in the flow YAML file: πŸ‘‡πŸ»

action: Custom

Implementing the Channels

LowBot provides an interface to channels that you can implement. πŸš›

type Channel interface {
	SendAudio(Interaction) error
	SendButton(Interaction) error
	SendDocument(Interaction) error
	SendImage(Interaction) error
	SendText(Interaction) error
	SendVideo(Interaction) error
	Next(chan Interaction)
}

The Send methods receive an Interaction and should return an error.

The Next method receive a chan of Interaction, which is filled with the messages

Supported Channels

Channel Requirements Function
βœ… Telegram TELEGRAM_TOKEN NewTelegram
βœ… Discord DISCORD_TOKEN NewDiscord

Implementing the Persists

LowBot provides an interface to persist that you can implement. πŸ—ƒοΈ

type Persist interface {
	Set(flow *Flow) error
	Get(sessionID string) (*Flow, error)
}

The Set method receive an Flow and should return an error.

The Get method receive the SessionID of Flow, and should return a Flow and error.

Supported Persists

Channel Requirements Function
βœ… Local - NewLocalPersist

Examples

You can see some examples in examples folder.

Directories ΒΆ

Path Synopsis
examples
chatgpt command
dungeon command
hello command
pingpong command
tabnews command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL