|
1 | | -const {buildConfigurationForm, MAX_NUM_OF_OPTIONS} = require('./config-form'); |
2 | | -const {buildVoteCard} = require('./vote-card'); |
| 1 | +const {buildConfigurationForm, MAX_NUM_OF_OPTIONS} = require('./src/config-form'); |
| 2 | +const {buildVoteCard} = require('./src/vote-card'); |
3 | 3 | const {saveVotes} = require('./helpers/vote'); |
4 | | -const {buildAddOptionForm} = require('./add-option-form'); |
| 4 | +const {buildAddOptionForm} = require('./src/add-option-form'); |
5 | 5 | const {callMessageApi} = require('./helpers/api'); |
6 | 6 | const {addOptionToState} = require('./helpers/option'); |
| 7 | +const {buildActionResponse} = require('./helpers/response'); |
7 | 8 |
|
8 | 9 | /** |
9 | 10 | * App entry point. |
| 11 | + * @param {object} req - chat event |
| 12 | + * @param {object} res - chat event |
| 13 | + * @returns {void} |
10 | 14 | */ |
11 | 15 | exports.app = async (req, res) => { |
12 | 16 | if (!(req.method === 'POST' && req.body)) { |
@@ -75,7 +79,7 @@ async function startPoll(event) { |
75 | 79 | // Get the form values |
76 | 80 | const formValues = event.common?.formInputs; |
77 | 81 | const topic = formValues?.['topic']?.stringInputs.value[0]?.trim(); |
78 | | - const is_anonymous = formValues?.['is_anonymous']?.stringInputs.value[0] === |
| 82 | + const isAnonymous = formValues?.['is_anonymous']?.stringInputs.value[0] === |
79 | 83 | '1'; |
80 | 84 | const choices = []; |
81 | 85 | const votes = {}; |
@@ -113,7 +117,7 @@ async function startPoll(event) { |
113 | 117 | author: event.user, |
114 | 118 | choices: choices, |
115 | 119 | votes: votes, |
116 | | - anon: is_anonymous, |
| 120 | + anon: isAnonymous, |
117 | 121 | }); |
118 | 122 | const message = { |
119 | 123 | cardsV2: [pollCard], |
@@ -162,13 +166,13 @@ function recordVote(event) { |
162 | 166 | * |
163 | 167 | * @param {object} event the event object from Google Chat. |
164 | 168 | * |
165 | | - * @return {object} open a dialog. |
| 169 | + * @returns {object} open a dialog. |
166 | 170 | */ |
167 | 171 | function addOptionForm(event) { |
168 | | - |
169 | | - const stateJson = event.message.cardsV2[0].card.sections[0].widgets[0].decoratedText.button.onClick.action.parameters[0].value; |
| 172 | + const card = event.message.cardsV2[0].card; |
| 173 | + const stateJson = card.sections[0].widgets[0].decoratedText.button.onClick.action.parameters[0].value; |
170 | 174 | const state = JSON.parse(stateJson); |
171 | | - const dialog = buildAddOptionForm(state, event.message.thread); |
| 175 | + const dialog = buildAddOptionForm(state); |
172 | 176 | return { |
173 | 177 | actionResponse: { |
174 | 178 | type: 'DIALOG', |
|
0 commit comments