nodes

package
v0.0.0-...-6f48dd4 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2023 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BotSendMessageAction = &logic.Node[BotSendMessageArgs, Empty]{
	ID:   uuid.MustParse("7b42a5e7-0c59-4034-94f9-8310c531e521"),
	Type: logic.NodeTypeAction,
	Func: func(ctx context.Context, input *BotSendMessageArgs) (*Empty, error) {
		bot, ok := ctx.Value(BotContextValue).(*telego.Bot)
		if !ok {
			return nil, fmt.Errorf("no context value %q", BotContextValue)
		}

		_, err := bot.SendMessage(tu.Message(tu.ID(input.ChatID), input.Text))
		if err != nil {
			return nil, err
		}

		return &Empty{}, nil
	},
}
View Source
var BotUpdateEvent = &logic.Node[Empty, BotUpdate]{
	ID:   uuid.MustParse("ab2283b9-2553-474f-9d8c-14267eb026af"),
	Type: logic.NodeTypeEvent,
	Func: func(ctx context.Context, _ *Empty) (*BotUpdate, error) {
		update, ok := ctx.Value(BotUpdateContextValue).(telego.Update)
		if !ok {
			return nil, fmt.Errorf("no context value %q", BotUpdateContextValue)
		}

		upd := &BotUpdate{
			UpdateID: int64(update.UpdateID),
		}

		if update.Message != nil {
			message := update.Message

			upd.Message = &BotMessage{
				ID: int64(message.MessageID),
				Chat: BotChat{
					ID: message.Chat.ID,
				},
				Text: message.Text,
			}
		}

		return upd, nil
	},
}

Functions

This section is empty.

Types

type BotChat

type BotChat struct {
	ID int64 `json:"id"`
}

type BotMessage

type BotMessage struct {
	ID   int64   `json:"id"`
	Chat BotChat `json:"chat"`
	Text string  `json:"text"`
}

type BotSendMessageArgs

type BotSendMessageArgs struct {
	ChatID int64  `json:"chatID"`
	Text   string `json:"text"`
}

type BotUpdate

type BotUpdate struct {
	UpdateID int64       `json:"updateID"`
	Message  *BotMessage `json:"message,omitempty"`
}

type ContextValue

type ContextValue string
const BotContextValue ContextValue = "bot"
const BotUpdateContextValue ContextValue = "bot-update"

type Empty

type Empty struct{}

Jump to

Keyboard shortcuts

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