Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generalized random responder (replacing dag bot) #155

Merged
merged 2 commits into from
Dec 28, 2018

Conversation

mgwalker
Copy link
Member

Adds a generalized, configurable script to autorespond to different triggers. Removes the specific dag bot and replaces it with a configuration for the new autoresponder script. Moves dag facts to another repo. This paves the way for cat bot to be cool like dag bot.

Configuration

In config/slack-random-response.json is an array of responses. A response is defined with an object that looks like this:

{
  botName: "Dag Bot",
  defaultEmoji: ":dog:",
  trigger: "d(o|a)g facts?",
  responseList: [],
  responseUrl: "url"
}
property description
botName optional If provided, the name the bot should use when serving this response.
defaultEmoji optional If provided, the emoji the bot should use as its avatar when serving this response.
trigger A string that will be turned into a regex, used to specify what triggers the response. This can also be an array of regex strings.
responseList An array of response items (describe below). The bot will select one at random to reply with. Either responseList or responseUrl is required. If both are provided, only responseList is used.
responseUrl The URL to a JSON file containing an array of response items. The bot will select one at random to reply with. Either responseList or responseUrl is required. If both are provided, only responseList is used.

Response items

Strings

A response item can be a string or an object. If the response item is a string and it begins with :emoji-name:, then the specified emoji will be used as the bot's avatar for the response, and only the text after :emoji-name: will be sent as the response. E.g., ":cat: Cats are animals" produces

screen shot 2018-12-28 at 10 26 39 am

If it doesn't begin with an emoji, the bot will use the defautlEmoji from the config, or else it won't specify an avatar and will use whatever was configured in Slack.

Objects

Response items can also be objects like this:

{
  name: "bot name",
  emoji: ":emoji:",
  text: "response text"
}
property description
name optional If set, the bot name to use when responding. If the bot config also includes a botName property, they are combined into name (botName)
emoji optional If set, the emoji to use as the bot's avatar for this response.
text required The text to respond with.

E.g.,

{
  name: "Dog in Disguise",
  emoji: ":dog:",
  text: "I am not a cat"

on a config with botName set to "Kitty Bot" produces:

screen shot 2018-12-28 at 10 41 15 am

cachedRequests[config.responseUrl] = {
expiry: Date.now() + 60000, // five minutes
value: JSON.parse(body)
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think I'm clear on the 5 minutes caching here. What are we doing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments incoming, but the idea is not to make the network hit on every single response. Instead, it caches off the network result for five minutes before re-refetching it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does that mean if call dag fact twice in a five minute window it'll give the same response, or that it only fetches the json every 5 max?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latter. You'll still get a random response, but it'll only fetch the JSON every five minutes.

Copy link
Contributor

@tbaxter-18f tbaxter-18f left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, and thanks for the clarifications, Greg

@tbaxter-18f tbaxter-18f merged commit 6dfe594 into master Dec 28, 2018
@mgwalker mgwalker deleted the mgwalker/random-responder-script branch September 3, 2021 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants