Skip to content

Instantly share code, notes, and snippets.

@nemo
Last active May 23, 2018 20:30
Show Gist options
  • Save nemo/ff9ed91f7ffc2168d44c951d16f75d9b to your computer and use it in GitHub Desktop.
Save nemo/ff9ed91f7ffc2168d44c951d16f75d9b to your computer and use it in GitHub Desktop.
You don't have to edit MessageBird or AscendDB's code. Create a new service with the following code!
const lib = require('lib')({ token: process.env.STDLIB_TOKEN })
const peaks = lib.ascendb.peaks['@1.0.0'];
/**
* Messagebird SMS handler that fetches AscenDB stats
* @param {string} sender The phone number that sent the text to be handled
* @param {string} receiver The StdLib phone number that received the SMS
* @param {string} message The contents of the SMS
* @param {string} createdDatetime Datetime when the SMS was sent
* @returns {object}
*/
module.exports = async (sender, receiver, message, createdDatetime, context) => {
console.log('not found, sender', sender, 'receiver', receiver, 'message', message, 'createdDatetime', createdDatetime)
let [result] = await peaks({
fields: [
'elev',
'prom',
'names',
'lat',
'lon',
'ors'
],
filters: {
name: message
}
});
let replyText = result ?
`${result.names && result.names[0].name} has an elevation of ${result.elev} feet and a prominence of ${result.prom} feet.` :
`Could not find ascendb info matching ${message}`
return lib.messagebird.sms.create({
originator: receiver,
recipient: sender,
body: replyText
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment