OptOut - 18F/charlie GitHub Wiki

Charlie developer documentation > Opt-out

The opt-out utility helps bots implement opt-out functionality. It's not a 100% solution for bots, but it does help a bunch.

function optOut(String key, String name, String description) : Object

Argument Description
key A unique key identifying the bot
name A user-friendly name of the bot, used to identify it on the Charlie home page so users can opt-in/out with checkboxes
description A description of the bot, also displayed on Charlie's home page

Returns

  • An object containing two properties.

    • The Slack Block Kit button object that should be included as a block in messages that your bot sends. This button is configured such that when a user clicks it, the optOut bot is triggered and opts the user out of the source bot. If your bot does not include the button object in its message, users will only be able to opt-out from Charlie's home page.
    • A utility function bots can use to check if a user is opted-out.

    The returned object looks essentially like this:

    {
      button: Object,
      isOptedOut: function(userId) : Bool,
    }
    

    The button property should simply be added to the bot's message as a block. E.g.,:

    const optout = optOut("my bot", "Docu-bot", "Documentation bot");
    
    say({
      blocks: [optout.button],
      text: "This is my bot's response!",
    });
    

property optOutOptions

When a bot calls the optOut function, its info gets added to a list of registered bots. This property exposes that list. It is used by Charlie's home page to build up the list of opt-in/out checkboxes. Other bots can also use it, but they currently don't.