Skip to content

Commit

Permalink
fix(builtin): added removeVariable action (#11364)
Browse files Browse the repository at this point in the history
* create removeVariable action

* update tooltip docs
  • Loading branch information
Raid55 committed Feb 1, 2022
1 parent 0b62e0e commit bb3e132
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions modules/builtin/src/actions/removeVariable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Remove a variable from storage.
*
* @title Remove Variable
* @category Storage
* @author Botpress, Inc.
* @param {string} type - Pick between: user, session, temp, bot
* @param {string} name - The name of the variable
*/
const removeVariable = async (type, name) => {
if (type === 'bot') {
const original = await bp.kvs.forBot(event.botId).get('global')
await bp.kvs.forBot(event.botId).set('global', { ...original, [name]: 'null' })
} else {
delete event.state[type][name]
}
}

return removeVariable(args.type, args.name)
2 changes: 1 addition & 1 deletion modules/builtin/src/actions/setVariable.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @author Botpress, Inc.
* @param {string} type - Pick between: user, session, temp, bot
* @param {string} name - The name of the variable
* @param {any} value - Set the value of the variable. Type 'null' or leave empty to erase it.
* @param {any} value - Set the value of the variable.
*/
const setVariable = async (type, name, value) => {
if (type === 'bot') {
Expand Down

0 comments on commit bb3e132

Please sign in to comment.