lowbot

package module
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2023 License: MIT Imports: 13 Imported by: 1

README ΒΆ

lowbot

πŸ€– LowBot is a Go project on GitHub that simplifies bot creation by automatically generating bot journeys from a YAML script. It offers extensive customization options, making it highly versatile and adaptable.

πŸ€” Why LowBot?

  • πŸ“š Simple and Self-Explanatory Scripting:

    LowBot follows a straightforward and intuitive YAML script format, making it easy to understand and modify for creating bot journeys.

  • 🧩 Extensibility for Custom Business Rules:

    LowBot offers extensive flexibility, allowing users to define their own custom actions and implement unique business rules tailored to their specific requirements.

  • πŸ“‘ Expandable Bot Channels:

    With LowBot, users can seamlessly integrate and implement their own channels, empowering them to connect the bot with various platforms and communication channels of their choice.

πŸ“¦ Install

go get github.com/chrissgon/lowbot

πŸš€ Quick Start

Start a bot with Telegram and local persist

import "github.com/chrissgon/lowbot"

flow, _ := lowbot.NewFlow("your_flow.yaml")
channel, _ := lowbot.NewTelegram()
persist, _ := lowbot.NewLocalPersist()

lowbot.StartBot(flow, channel, persist)

Start a bot with Discord and custom actions

import "github.com/chrissgon/lowbot"

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

lowbot.SetCustomActions(myActions)

flow, _ := lowbot.NewFlow("your_flow.yaml")
channel, _ := lowbot.NewDiscord()
persist, _ := lowbot.NewLocalPersist()

lowbot.StartBot(flow, channel, persist)

You can create your Channel or Persist by implementing their interfaces

import "github.com/chrissgon/lowbot"

func MyNewChannel () lowbot.Channel {
  // implements Channel
}

func MyNewPersist () lowbot.Persist {
  // implements Persist
}

flow, _ := lowbot.NewFlow("your_flow.yaml")

// And you can pass in the StartBot
lowbot.StartBot(flow, MyNewChannel(), MyNewPersist())

πŸ“š Documentation

Read all documentation in docs folder.

🌎 Global Variables

When you run this project, you can adjusts the following environment variables.

Debug: Show debug => default: true

EnableLocalPersist: Enable local persist => default: true

πŸ”’ Environment Variables

When you run this project, you need set the following environment variables.

  • When you to use Telegram:
    TELEGRAM_TOKEN: Telegram bot token.
  • When you to use Discord:
    DISCORD_TOKEN: Discord bot token.

πŸ’ͺ🏻 Contribution

This project is open source and welcomes community contributions. Feel free to fork, implement improvements, and submit a pull request. Every contribution is valued and appreciated!

We hope that lowbot proves useful to you and enhances your manga reading experience. Feel free to explore the source code, provide feedback, and report any issues you encounter.

πŸ’š Authors

Documentation ΒΆ

Index ΒΆ

Constants ΒΆ

This section is empty.

Variables ΒΆ

View Source
var Debug = true
View Source
var EnableLocalPersist = true

Functions ΒΆ

func ActionAudio ΒΆ

func ActionAudio(flow *Flow, channel Channel) (bool, error)

func ActionButton ΒΆ

func ActionButton(flow *Flow, channel Channel) (bool, error)

func ActionDocument ΒΆ

func ActionDocument(flow *Flow, channel Channel) (bool, error)

func ActionImage ΒΆ

func ActionImage(flow *Flow, channel Channel) (bool, error)

func ActionInput ΒΆ

func ActionInput(flow *Flow, channel Channel) (bool, error)

func ActionText ΒΆ

func ActionText(flow *Flow, channel Channel) (bool, error)

func ActionVideo ΒΆ

func ActionVideo(flow *Flow, channel Channel) (bool, error)

func ActionWait ΒΆ added in v1.5.2

func ActionWait(flow *Flow, channel Channel) (bool, error)

func FormatTestError ΒΆ

func FormatTestError(expect, have interface{}) string

func Int64ToString ΒΆ

func Int64ToString(number int64) string

func IsURL ΒΆ

func IsURL(str string) bool

func NewError ΒΆ added in v1.4.0

func NewError(fn string, err error) error

func ParseTemplate ΒΆ

func ParseTemplate(texts []string) string

func RunAction ΒΆ

func RunAction(flow *Flow, channel Channel) (bool, error)

func RunActionError ΒΆ

func RunActionError(flow *Flow, channel Channel) (bool, error)

func SetCustomActions ΒΆ added in v1.1.0

func SetCustomActions(custom ActionsMap)

func StartBot ΒΆ

func StartBot(base Flow, channel Channel, persist Persist) error

func StringToInt64 ΒΆ

func StringToInt64(str string) int64

Types ΒΆ

type ActionsMap ΒΆ

type ActionsMap map[string]func(flow *Flow, channel Channel) (bool, error)

type Channel ΒΆ

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

func NewDiscord ΒΆ added in v1.4.0

func NewDiscord() (Channel, error)

func NewTelegram ΒΆ

func NewTelegram() (Channel, error)

type Discord ΒΆ added in v1.4.0

type Discord struct {
	// contains filtered or unexported fields
}

func (*Discord) Next ΒΆ added in v1.4.0

func (ds *Discord) Next(in chan Interaction)

func (*Discord) RespondInteraction ΒΆ added in v1.4.0

func (ds *Discord) RespondInteraction(in *discordgo.Interaction)

func (*Discord) SendAudio ΒΆ added in v1.4.0

func (ds *Discord) SendAudio(in Interaction) error

func (*Discord) SendButton ΒΆ added in v1.4.0

func (ds *Discord) SendButton(in Interaction) error

func (*Discord) SendDocument ΒΆ added in v1.4.0

func (ds *Discord) SendDocument(in Interaction) error

func (*Discord) SendFile ΒΆ added in v1.4.0

func (ds *Discord) SendFile(sessionID, text, path string) error

func (*Discord) SendImage ΒΆ added in v1.4.0

func (ds *Discord) SendImage(in Interaction) error

func (*Discord) SendText ΒΆ added in v1.4.0

func (ds *Discord) SendText(in Interaction) error

func (*Discord) SendVideo ΒΆ added in v1.4.0

func (ds *Discord) SendVideo(in Interaction) error

type Flow ΒΆ

type Flow struct {
	SessionID string
	Name      string `yaml:"name"`
	Steps     Steps  `yaml:"steps"`
	Current   *Step
}

func NewFlow ΒΆ

func NewFlow(path string) (Flow, error)

func (*Flow) End ΒΆ

func (flow *Flow) End() *Flow

func (*Flow) IsEnd ΒΆ

func (flow *Flow) IsEnd() bool

func (*Flow) Next ΒΆ

func (flow *Flow) Next(in Interaction) *Flow

func (*Flow) NoHasNext ΒΆ added in v1.4.0

func (flow *Flow) NoHasNext() bool

func (*Flow) Start ΒΆ

func (flow *Flow) Start()

type Interaction ΒΆ

type Interaction struct {
	SessionID  string                `json:"sessionID"`
	Type       InteractionType       `json:"type"`
	Parameters InteractionParameters `json:"parameters"`
	Custom     map[string]any        `json:"custom"`
}

func NewInteractionMessageAudio ΒΆ

func NewInteractionMessageAudio(sessionID string, audio string, text string) Interaction

func NewInteractionMessageButton ΒΆ

func NewInteractionMessageButton(sessionID string, buttons []string, text string) Interaction

func NewInteractionMessageDocument ΒΆ

func NewInteractionMessageDocument(sessionID string, document string, text string) Interaction

func NewInteractionMessageImage ΒΆ

func NewInteractionMessageImage(sessionID string, image string, text string) Interaction

func NewInteractionMessageText ΒΆ

func NewInteractionMessageText(sessionID string, text string) Interaction

func NewInteractionMessageVideo ΒΆ

func NewInteractionMessageVideo(sessionID string, video string, text string) Interaction

type InteractionParameters ΒΆ

type InteractionParameters StepParameters

type InteractionType ΒΆ

type InteractionType string
const (
	MESSAGE InteractionType = "message"
	EVENT                   = "event"
)

type Local ΒΆ added in v1.4.0

type Local struct {
	Sessions map[string]*Flow
}

func (*Local) Get ΒΆ added in v1.4.0

func (loc *Local) Get(sessionID string) (*Flow, error)

func (*Local) Load ΒΆ added in v1.4.0

func (loc *Local) Load() error

func (*Local) Set ΒΆ added in v1.4.0

func (loc *Local) Set(flow *Flow) error

type Persist ΒΆ added in v1.4.0

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

func NewLocalPersist ΒΆ added in v1.4.0

func NewLocalPersist() (Persist, error)

type Step ΒΆ

type Step struct {
	Action     string            `yaml:"action"`
	Next       map[string]string `yaml:"next"`
	Parameters StepParameters    `yaml:"parameters"`
	Responses  []Interaction
}

func (*Step) AddResponse ΒΆ added in v1.4.0

func (step *Step) AddResponse(in Interaction)

func (*Step) GetLastResponse ΒΆ added in v1.4.2

func (step *Step) GetLastResponse() Interaction

func (*Step) GetLastResponseText ΒΆ added in v1.4.2

func (step *Step) GetLastResponseText() string

type StepParameters ΒΆ

type StepParameters struct {
	Audio    string   `yaml:"audio" json:"audio"`
	Buttons  []string `yaml:"buttons" json:"buttons"`
	Document string   `yaml:"document" json:"document"`
	Image    string   `yaml:"image" json:"image"`
	Text     string   `yaml:"text" json:"text"`
	Texts    []string `yaml:"texts"`
	Video    string   `yaml:"video" json:"video"`
}

type Steps ΒΆ

type Steps map[string]*Step

type Telegram ΒΆ

type Telegram struct {
	// contains filtered or unexported fields
}

func (*Telegram) Next ΒΆ

func (tg *Telegram) Next(in chan Interaction)

func (*Telegram) SendAudio ΒΆ

func (tg *Telegram) SendAudio(in Interaction) error

func (*Telegram) SendButton ΒΆ

func (tg *Telegram) SendButton(in Interaction) error

func (*Telegram) SendDocument ΒΆ

func (tg *Telegram) SendDocument(in Interaction) error

func (*Telegram) SendImage ΒΆ

func (tg *Telegram) SendImage(in Interaction) error

func (*Telegram) SendText ΒΆ

func (tg *Telegram) SendText(in Interaction) error

func (*Telegram) SendVideo ΒΆ

func (tg *Telegram) SendVideo(in Interaction) error

Directories ΒΆ

Path Synopsis
docs

Jump to

Keyboard shortcuts

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