Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/willin/tuling
图灵机器人SDK for Node.js
https://github.com/willin/tuling
bot sdk tuling
Last synced: 27 days ago
JSON representation
图灵机器人SDK for Node.js
- Host: GitHub
- URL: https://github.com/willin/tuling
- Owner: willin
- Created: 2016-06-08T09:15:52.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-07T08:38:09.000Z (over 7 years ago)
- Last Synced: 2024-04-14T04:55:39.056Z (7 months ago)
- Topics: bot, sdk, tuling
- Language: JavaScript
- Homepage:
- Size: 19.5 KB
- Stars: 9
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 图灵机器人SDK
[![npm](https://img.shields.io/npm/v/tuling.svg?style=plastic)](https://npmjs.org/package/tuling) [![npm](https://img.shields.io/npm/dm/tuling.svg?style=plastic)](https://npmjs.org/package/tuling)
[![npm](https://img.shields.io/npm/dt/tuling.svg?style=plastic)](https://npmjs.org/package/tuling)## 安装
```bash
npm install --save tuling
```## 使用
ES7:
```js
const TULING = require('tuling');const tuling = new TULING({key: 'xxx'});
(async() => {
const result = await tuling.send({
userid: 1,
info: '你好吗',
loc: '南京市'
});
console.log(result);
})();
```ES5:
```js
var TULING = require('tuling');var tuling = new TULING({key: 'xxx'});
tuling.send({
userid: 1,
info: '你好吗',
loc: '南京市'
}).then(function(result) {
console.log(result);
})
```## 进阶
微信语音识别接入简单示例:
```js
var TULING = require('tuling');
var wechat = require('wechat');
var express = require('express');// 填入配置项
var config = {
token: 'xxxx',
appid: 'xxxx',
encodingAESKey: 'xxxx'
};
var tuling = new TULING({key: 'xxxx'});var app = express();
app.use(express.query());app.use('/', wechat(config, function (req, res, next) {
var message = req.weixin;
console.log(message);
if(message.Event!==undefined && message.Event ==='subscribe'){
return res.reply('欢迎关注xxxx,目前正处于测试阶段。');
}
if(message.MsgType==='text' || message.MsgType==='voice'){
return tuling.send({
userid: message.FromUserName,
info: message.Content || message.Recognition
}).then(function(result){
switch (result.code) {
case 200000:
return res.reply(''+result.text+'');
break;
case 302000:
var html = result.text;
for(item of result.list){
if(item.article!==''){
html+= ','+item.article+''
}
}return res.reply(html);
break;
case 308000:
var html = result.text;
for(item of result.list){
html+=','+item.name+''
}return res.reply(html);
break;
default:
return res.reply(result.text);
}
});
}
}));app.listen(8080);
```## License
MIT
通过支付宝捐赠:
![qr](https://cloud.githubusercontent.com/assets/1890238/15489630/fccbb9cc-2193-11e6-9fed-b93c59d6ef37.png)