Skip to content

Latest commit

 

History

History
114 lines (76 loc) · 4.12 KB

README.md

File metadata and controls

114 lines (76 loc) · 4.12 KB

Actions

Actions are the set of operations that are executed in response to certain validation or criteria fulfillment. This could range from sending reply posts, logging particular information, or executing any function, to more complex sequences of operations. You even have the ability to create custom actions based on your needs.

Provided Actions

Creating your own action

Actions are fairly simple, it should extend AbstractMessageAction and have constructor and handle functions.

The handle function is what's called if the validations pass.

export class ExampleAction extends AbstractMessageAction {
    constructor() {
        super();
    }

    async handle(
      handlerAgent: HandlerAgent,
        message: JetstreamMessage
    ): Promise<any> {
        // Perform your actions here
    }
}

Any additional parameters you may need for the action can be passed into the constructor and used within the handle function as needed, like so

export class ExampleAction extends AbstractMessageAction {
    constructor(private userDid: string) {
        super();
    }

    async handle(
      handlerAgent: HandlerAgent,
        message: JetstreamMessage
    ): Promise<any> {
        // use this.userDid to access the property
        // Perform your actions here
    }
}

FunctionAction

The FunctionAction class takes a function as an argument. This function gets executed when the handle method is called and it should accept JeststreamMessage and HandlerAgent as arguments.

FunctionAction.make((handlerAgent, message) => { // Function implementation goes here });

Logging Actions

LogMessageAction

The LogMessageAction class logs message received from jetstream.

LogMessageAction.make();

LogInputTextAction

The LogInputTextAction class logs given input text.

LogInputTextAction.make("input text")

DebugLogAction

The DebugLogAction class will output to the log using the DebugLog class. give it the action, the message, and log level

DebugLogAction.make("Action", "Text", info|warn|error);

Skeet Actions

These are older functions, Use actions in standard-bsky-actions instead!

CreateSkeetAction

Pass in a string, and when the validations pass, it will create a new skeet from the agent with the given input text.

CreateSkeetAction.make("Skeet text")

CreateSkeetWithGeneratedTextAction

The CreateSkeetWithGeneratedTextAction accepts a function with 2 arguments, JetstreamMessage and HandlerAgent. This function should return a string When the validations pass, it will call the function to generate the response text

CreateSkeetWithGeneratedTextAction.make((handlerAgent, message: JetstreamMessage) => { // Function implementation goes here });

ReplyToSkeetAction

The ReplyToSkeetAction only works on post creation messages for now. Pass in a string, and when the validations pass, it will reply to the created skeet with a new skeet using the given input text

ReplyToSkeetAction.make("JetstreamReply Text")

ReplyToSkeetWithGeneratedTextAction

The ReplyToSkeetWithGeneratedTextAction only works on post creation messages for now. Similar to the CreateSkeetWithGeneratedTextAction, it accepts a function with 2 arguments, but the first is a CreateSkeetMessage and the second is the same, being a HandlerAgent. This function should return a string When the validations pass, it will call the function to generate the response text

ReplyToSkeetWithGeneratedTextAction.make((handlerAgent, message: CreateSkeetMessage) => { // Function implementation goes here });