function processEvent(req, rsp) { var event = req.body; // event type received var message; // JSON response message if (event.type == 'REMOVED_FROM_SPACE') { // no response as bot removed from room return; } else if (event.type == 'ADDED_TO_SPACE') { // bot added to room; send welcome message message = {text: 'Thanks for adding me!'}; } else if (event.type == 'MESSAGE') { // message received during normal operation message = responseForMsg(event.message.text); } else if (event.type == 'CARD_CLICKED') { // user-click on card UI var action = event.action; message = responseForClick( action.actionMethodName, action.parameters); } rsp.send(message); };
/** * A helper function for building dropdown widgets */ function buildDropdownWidget(key, title, items, selected) { var widget = CardService.newSelectionInput() .setType(CardService.SelectionInputType.DROPDOWN) .setTitle(title) .setFieldName(key) for(var i = 0; i < items.length; i++) { var itemSelected = selected === items[i].value widget.addItem(items[i].text, items[i].value, itemSelected) } return widget }