Skip to content
martiliones edited this page Jun 12, 2023 · 1 revision

Bot

createBot()

Creates new bot instance within given pass phrase and options

  • Type

    function createBot(passPhrase: string, options: botOptions): Bot;
  • References

    botOptions, Bot

botOptions

  • Type

    interface botOptions {
      enableSSL?: boolean;
      logger?: any;
      nodes: string[];
    }

bot.api

  • Type

    interface Bot {
      api: Api;
    }
    
    class Api {}

bot.handleError

Error handler set via Bot.catch()

  • Type

    interface Bot {
      handleError: ErrorHandler;
    }
  • References

    ErrorHandler

bot.catch()

Sets the bot's error handler

  • Type

    interface Bot {
      catch(handleError: ErrorHandler): void;
    }
  • References

    ErrorHandler

bot.command()

Registers some middleware that will only be executed when the bot received a message that starts with the specifid command.

  • Type

    interface Bot {
      command(name: string, ...handlers: Handler[]): void;
    }
  • Details

    The commands must meet the following criteria:

    • The command must start with a forward slash character (/).
    • The command must be composed of one or more uppercase or lowercase letters.
    • The letters in the command may be separated by one underscore (_).
    • The command must end with a single letter.
  • Example

    The following route will match /hello command

    bot.command('hello', () => {})
  • References

    Handler

bot.handle()

Decodes and processes a new transaction, could be used for testing or handling transactions from other sources

  • Type

    interface Bot {
      handle(transaction: CryptedTransaction): void;
    }

bot.hears()

Registers some middleware(s) that will only be executed when the message contains some text specified by pattern

  • Type

    interface Bot {
      hears(pattern: Pattern, ...handlers: Handler[]): void;
    }
  • Example

    This route will match butterfly and dragonfly, but not butterflyman, dragonflyman, and so on.

    bot.hears(/.*fly$/, () => {})
  • References

    Pattern, Handler

bot.start()

Starts the webhook client and listens for new messages

  • Type

    interface Bot {
      start(): void;
    }

bot.use()

Registers some middleware

  • Type

    interface Bot {
      use(...handlers: Handler[]): void;
    }
  • References

    Handler

Clone this wiki locally