Skip to content

Instantly share code, notes, and snippets.

@tonygentilcore
Last active December 28, 2016 19:30
Show Gist options
  • Save tonygentilcore/9228359d3fe43c759fccc3ab598a0875 to your computer and use it in GitHub Desktop.
Save tonygentilcore/9228359d3fe43c759fccc3ab598a0875 to your computer and use it in GitHub Desktop.
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