-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
32 lines (27 loc) · 900 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Commands:
// hubot what is this [URL] - Identify the contents of an image
//
const Clarifai = require('clarifai')
module.exports = (robot) => {
const apiKey = process.env.HUBOT_CLARIFAI_API_KEY
if (!apiKey) {
robot.logger.error('No API key provided for hubot-clarifai... disabling...')
return
}
const app = new Clarifai.App({ apiKey })
return robot.respond(/what is (?:this |)(.*)/i, (msg) => {
const { match: [, query] } = msg
app.models.predict(Clarifai.GENERAL_MODEL, query).then(
(response) => {
const outputs = response.outputs.map((output) => {
return output.data.concepts.map(concept => concept.name).join(', ')
})
msg.send(`I'm seeing ${outputs}.`)
},
(err) => {
robot.logger.info(`Failed to fetch request #{request} - statusText: ${err.statusText}`)
msg.send('wat')
}
)
})
}