Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// backend/src/controllers/v1/message.js
const handleMessage = (userId, result) => {
let text = '';
if (result.intent.displayName === 'Check Accounts') {
text = `Here are your balances\nChecking: $${balances[userId].checking}\nSavings: $${balances[userId].savings}`;
} else if (result.intent.displayName === 'Transfer Money') {
const parameters = struct.decode(result.parameters);
const transfer = parameters.transfer;
const amount = parameters.amount.amount;
if (transfer === 'checking to savings') {
balances[userId].checking -= amount;
balances[userId].savings += amount;
text = result.fulfillmentText;
} else if (transfer === 'savings to checking') {
balances[userId].checking += amount;
balances[userId].savings -= amount;
text = result.fulfillmentText;
} else {
text = 'Failed to transfer, unknown accounts';
}
} else {
text = result.fulfillmentText;
}
return text;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.