lita-confirmation
lita-confirmation is an extension for Lita that allows handler routes to require "confirmation" before being triggered. Confirmation consists of a second message sent to the robot with a confirmation code.
Installation
Add lita-confirmation to your Lita plugin's gemspec:
spec.add_runtime_dependency "lita-confirmation"
Usage
Basic confirmation
For basic confirmation, simply set the :confirmation
option to true when defining a route.
route /danger/, :danger, command: true, confirmation: true
This will result in the following behavior:
Alice: Lita, danger
Lita: This command requires confirmation. To confirm, send the command: Lita confirm 636f308
Alice: Lita, confirm 636f308
Lita: Dangerous command executed!
Customized confirmation
There are a few different options that can be supplied to customize the way the confirmation behaves. To supply one or more options, pass a hash as the value for the :confirmation
option instead of just a boolean.
allow_self
By default, the same user who initially triggered the command can confirm it. If you want to make it even harder to trigger a command accidentally, you can require that another user send the confirmation command by setting the :allow_self
option to false.
route /danger/, :danger, command: true, confirmation: { allow_self: false }
Alice: Lita, danger
Lita: This command requires confirmation. To confirm, send the command: Lita confirm 636f308
Alice: Lita, confirm 636f308
Lita: Confirmation 636f308 must come from a different user.
Bob: Lita, confirm 636f308
Lita: Dangerous command executed!
restrict_to
If you want to require that the confirming user be a member of a particular authorization group, use the :restrict_to
option. The value can be either a string, a symbol, or an array or strings/symbols.
route /danger/, :danger, command: true, confirmation: { restrict_to: :managers }
Alice: Lita, danger
Lita: This command requires confirmation. To confirm, send the command: Lita confirm 636f308
Alice: Lita, confirm 636f308
Lita: Confirmation 636f308 must come from a user in one of the following authorization groups: managers
Manager: Lita, confirm 636f308
Lita: Dangerous command executed!
expire_after
By default, a confirmation must be made within one minute of the original command. After the expiry period, the original command must be sent again, and a new confirmation code will be generated. To change the length of the expiry, set the :expire_after
value to an integer or string number of seconds.
route /danger/, :danger, command: true, confirmation: { expire_after: 10 }
Alice: Lita, danger
Lita: This command requires confirmation. To confirm, send the command: Lita confirm 636f308
Alice: Waiting 15 seconds...
Alice: Lita, confirm 636f308
Lita: 636f308 is not a valid confirmation code. It may have expired. Please run the original command again.