Created
July 19, 2018 04:17
-
-
Save zaoldyeck/5b42701578f9708099f7b455cda9f0da 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 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