UNPKG

bottender-compose

Version:

An utility library for bottender and higher-order handlers

20 lines (16 loc) 421 B
"use strict"; const randomItem = require('random-item'); const { withProps } = require('bottender'); module.exports = actions => { const Fn = async (context, props) => { return withProps(randomItem(actions), props); }; const names = actions.map(action => action.name || 'Anonymous'); const name = `Random(${names.join(', ')})`; Object.defineProperty(Fn, 'name', { value: name }); return Fn; };