Skip to content

Instantly share code, notes, and snippets.

@zaoldyeck
Created July 19, 2018 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zaoldyeck/5b42701578f9708099f7b455cda9f0da to your computer and use it in GitHub Desktop.
Save zaoldyeck/5b42701578f9708099f7b455cda9f0da to your computer and use it in GitHub Desktop.
const config = require('../../config')
const axios = require('axios')
const md5 = require('md5')
class Olami {
constructor(appKey = config.olami.appKey, appSecret = config.olami.appSectet, inputType = 1) {
this.URL = 'https://tw.olami.ai/cloudservice/api'
this.appKey = appKey
this.appSecret = appSecret
this.inputType = inputType
}
nli(text, cusid = null) {
const timestamp = Date.now()
return axios.post(this.URL, {}, {
params: {
appkey: this.appKey,
api: 'nli',
timestamp: timestamp,
sign: md5(`${this.appSecret}api=nliappkey=${this.appKey}timestamp=${timestamp}${this.appSecret}`),
cusid: cusid,
rq: JSON.stringify({'data_type': 'stt', 'data': {'input_type': this.inputType, 'text': text}})
}
}).then(response => {
return response.data.data.nli[0].desc_obj.result
})
}
}
module.exports = new Olami()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment