Last active
December 28, 2016 19:30
-
-
Save tonygentilcore/9228359d3fe43c759fccc3ab598a0875 to your computer and use it in GitHub Desktop.
This file contains 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
const {fetch, Feature} = require('other') | |
const feature = new Feature({ | |
name: 'Duck Duck Go', | |
version: '0.0.8', | |
dependencies: { | |
otherjs: '^3.6.x', | |
}, | |
}) | |
feature.listen({ | |
to: {words: ['find', 'search', 'web']}, | |
on({word, rest}) { | |
const query = encodeURIComponent(rest.replace(word, '').trim()) | |
const url = `https://api.duckduckgo.com/?q=${query}&format=json` | |
return fetch(url).then((response) => response.json()).then((json) => { | |
if (!json.RelatedTopics) return null | |
return { | |
chatCompletions: json.RelatedTopics.map((topic) => { | |
return {text: topic.Text} | |
}) | |
} | |
}) | |
}, | |
}) | |
module.exports = feature |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment