Created
September 9, 2019 10:59
-
-
Save ekpangmichael/6f3f10ebecffd5e79c76fc45502cba1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class WhatsappBot { | |
/** | |
* @memberof WhatsappBot | |
* @param {object} req - Request sent to the route | |
* @param {object} res - Response sent from the controller | |
* @param {object} next - Error handler | |
* @returns {object} - object representing response message | |
*/ | |
static async googleSearch(req, res, next) { | |
const twiml = new MessagingResponse(); | |
const q = req.body.Body; | |
const options = { cx, q, auth: googleApiKey }; | |
try { | |
const result = await customsearch.cse.list(options); | |
const firstResult = result.data.items[0]; | |
const searchData = firstResult.snippet; | |
const link = firstResult.link; | |
twiml.message(`${searchData} ${link}`); | |
res.set('Content-Type', 'text/xml'); | |
return res.status(200).send(twiml.toString()); | |
} catch (error) { | |
return next(error); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment