Skip to content

Commit

Permalink
Merge pull request #5 from juanprado/master
Browse files Browse the repository at this point in the history
Adding bulk messaging with all of the contact info
  • Loading branch information
chrisdevwords committed Jan 14, 2017
2 parents 5c7770e + c43f084 commit 4215bf6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
16 changes: 12 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
getMembersByAddress,
parseDataToMessage,
parseErrorToMessage,
getContactInfo
getBulkContactMessage,
parseBulkMessages
} from './serivce-helper';

// eslint-disable-next-line babel/new-cap
Expand Down Expand Up @@ -67,11 +68,18 @@ const exitFunction = (req, res) => {
app.intent('AMAZON.YesIntent', (req, res) => {
const session = req.getSession();
const data = session.get('data');
const name = data.representative.name;

if (data) {
getContactInfo(name)
.then(({ message }) => {
const { senators, representative } = data;
const names = [
representative.name,
senators[0].name,
senators[1].name
];

getBulkContactMessage(names)
.then(parseBulkMessages)
.then((message) => {
res
.say(message)
.shouldEndSession(true)
Expand Down
16 changes: 11 additions & 5 deletions src/serivce-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ export function senioritySort(senators) {
);
}

export function parseContactMessage({ name, contact }) {
export function parseContactMessage(name, result) {
const message = `The phone number for ${name} is ${result.contact.phone}`

const message = `The phone number for ${name} is ${contact.phone}`;
return { message };
}

export function parseBulkMessages(messages) {
const bulkMessage = messages.map(({ message }) => message).join(' ');

return bulkMessage;
}

export function parseDataToMessage(result) {
const { senators, representative } = result;
const orderSenators = senioritySort(senators);
Expand Down Expand Up @@ -65,12 +71,12 @@ export function getContactInfo(name) {
};
return request
.get(options)
.then(parseContactMessage)
.then(result => parseContactMessage(name, result))
.catch(parseErrorToMessage);
}

export function getBulkContactMessage(names) {
return Promise.all(
names.map((name) => getContactInfo(name))
);
names.map(name => getContactInfo(name))
)
}

0 comments on commit 4215bf6

Please sign in to comment.