Documentation
¶
Index ¶
- Constants
- Variables
- type Bot
- func (b *Bot) MuteRequestHandler(ctx context.Context, msg *farcasterapi.APIMessage) (*farcasterapi.Userdata, *farcasterapi.APIMessage, bool, error)
- func (b *Bot) PollMessageHandler(ctx context.Context, msg *farcasterapi.APIMessage, maxDuration time.Duration) (*farcasterapi.Userdata, *poll.Poll, bool, error)
- func (b *Bot) ReplyWithPollURL(ctx context.Context, msg *farcasterapi.APIMessage, pollURL string) error
- func (b *Bot) Start(ctx context.Context)
- func (b *Bot) Stop()
- type BotConfig
- type CastAddBody
- type Message
- type MessageData
Constants ¶
const (
MESSAGE_TYPE_CAST_ADD = "MESSAGE_TYPE_CAST_ADD"
)
Variables ¶
var ( // ErrAPINotSet is returned when the API is not set in the bot configuration. ErrAPINotSet = fmt.Errorf("api not set") // ErrParsingPoll is returned when there is an error parsing the poll during // the poll message handler. ErrParsingPoll = fmt.Errorf("error parsing poll") // ErrGettingUserData is returned when there is an error getting user data // during the poll message handler. ErrGettingUserData = fmt.Errorf("error getting user data") // ErrReplyingToCast is returned when there is an error replying to a cast // during the reply with poll URL function. ErrReplyingToCast = fmt.Errorf("error replying to cast") // ErrGettingParentCast is returned when there is an error getting the parent // cast during the mute notifications message handler. ErrGettingParentCast = fmt.Errorf("error getting parent cast") )
var PollReplyTemplate = `` /* 216-byte string literal not displayed */
PollReplyTemplate is the template for the reply to a cast with a poll. It must be formatted with the poll URL.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct { UserData *farcasterapi.Userdata Messages chan *farcasterapi.APIMessage // contains filtered or unexported fields }
Bot struct represents a bot that listens for new casts and sends them to a channel, it also has a cool down time to avoid spamming the API and a last cast timestamp to retrieve new casts from that point, ensuring no cast is missed or duplicated
func New ¶
New function creates a new bot with the given configuration, it returns an error if the API is not set in the configuration.
func (*Bot) MuteRequestHandler ¶
func (b *Bot) MuteRequestHandler(ctx context.Context, msg *farcasterapi.APIMessage) (*farcasterapi.Userdata, *farcasterapi.APIMessage, bool, error)
func (*Bot) PollMessageHandler ¶
func (b *Bot) PollMessageHandler(ctx context.Context, msg *farcasterapi.APIMessage, maxDuration time.Duration) (*farcasterapi.Userdata, *poll.Poll, bool, error)
PollMessageHandler is a function that handles a new cast and checks if it is a poll, if it is, it parses the poll and returns the user data and the poll. If it is not a poll, it returns false. It returns an error if something goes wrong, including when message parsing fails.
func (*Bot) ReplyWithPollURL ¶
func (b *Bot) ReplyWithPollURL(ctx context.Context, msg *farcasterapi.APIMessage, pollURL string) error
type BotConfig ¶
type BotConfig struct { API farcasterapi.API CoolDown time.Duration }
BotConfig is the configuration definition for the bot, it includes the API instance and the cool down time between casts (default is 10 seconds)
type CastAddBody ¶
CastAddBody represents the body of a cast add message.
type Message ¶
type Message struct { Data *MessageData `json:"data"` HexHash string `json:"hash"` }
Message represents a message from the API, it includes the data and the hash of the message.
type MessageData ¶
type MessageData struct { Type string `json:"type"` From uint64 `json:"fid"` Timestamp uint64 `json:"timestamp"` CastAddBody *CastAddBody `json:"castAddBody,omitempty"` }
MessageData represents the data of a message.
Directories
¶
Path | Synopsis |
---|---|
poll package contains the logic to parse a poll message from a string and create a poll struct with the question, options and duration.
|
poll package contains the logic to parse a poll message from a string and create a poll struct with the question, options and duration. |