Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MessageCommands

Hierarchy

  • MessageCommands

Index

Methods

sendAsBot

  • sendAsBot(text: string, onUserReply?: undefined | ((event: MessageEventData) => void)): void
  • Opens the chat window (if not already open) and sends a message to the user as if from the bot. Executes the optionally-provided callback function when the user replies to the message (if they do so). Note: the bot will not "remember" that it sent this message, so any user replies will cause the bot to continue where it left off before this message was sent.

    Usage

    example
    // Send a message to the user saying "Hello!" as if from the bot
    Otis.messages.sendAsBot("Hello!");
    
    // Send a message to the user saying "Hello!" as if from the bot, and then
    // log details about their response to the console when they reply
    Otis.messages.sendAsBot("Hello!", (event) => {
      console.log("User said:", event.data.text);
      console.log("At:", new Date(event.data.timestamp));
      if (event.data.freeform) {
        console.log("(they sent this message by typing into the text box)");
      } else {
        console.log("(they sent this message by clicking a button)");
      }
    });

    Parameters

    • text: string

      Message text to send as if from the bot

    • Optional onUserReply: undefined | ((event: MessageEventData) => void)

      Callback function to be executed once the user replies (optional)

    Returns void

sendAsUser

  • sendAsUser(text: string, onBotReply?: undefined | ((event: MessageEventData) => void)): void
  • Opens the chat window (if not already open) and sends a message to the bot as if from the user. Executes the optionally-provided callback function when the bot replies to the message. The bot will not "know" the difference between this message and a message genuinely sent from the user.

    Usage

    example
    // Send a message to the bot so that it tells the user what this location's
    // business hours are
    Otis.messages.sendAsUser("When are you open?");
    
    // Send a message to the bot so that it tells the user what this location's
    // business hours are, then log details about the bot's response to the
    // console when it replies
    Otis.messages.sendAsUser("When are you open?", (event) => {
      console.log("Bot said:", event.data.text);
      console.log("At:", new Date(event.data.timestamp));
    });

    Parameters

    • text: string

      Message text to send as if from the bot

    • Optional onBotReply: undefined | ((event: MessageEventData) => void)

      Callback function to be executed once the user replies (optional)

    Returns void