被玩坏的垃圾分类微信机器人共享了

时间:2019-07-05 20:37:08

昨天分享的垃圾分类小程序很多人说不好看,有小伙伴已经根据示例源码改成了下面这个样子。根据天行机器人和垃圾分类API制作的微信自动聊天机器人也上线了,在多个微信群里测试良好。

被玩坏的垃圾分类微信机器人共享了

被玩坏的垃圾分类微信机器人共享了


使用方法,自己的电脑或服务器都可以,打开开源项目wechatBot链接https://github.com/gengchen528/wechatBot ,下载代码按提示安装相关node组件和配置参数:

被玩坏的垃圾分类微信机器人共享了


下载解压源码包后,打开superagent/index.js,在适当位置增加以下代码:


async function getLajifenlei(word) { // 垃圾分类
    let url = config.LAJIFENLEI
    let res = await superagent.req(url, 'GET', { key: config.APIKEY, word: word})
    let content = JSON.parse(res.text)
    if (content.code === 200) {
        console.log(content)
		let type
		if(content.newslist[0].type == 0){
			type = '是可回收垃圾'
		}else if(content.newslist[0].type == 1){
			type = '是有害垃圾'
		}else if(content.newslist[0].type == 2){
			type = '是厨余(湿)垃圾'
		}else if(content.newslist[0].type == 3){
			type = '是其他(干)垃圾'
		}
        let response = content.newslist[0].name + type + '<br>解释:' + content.newslist[0].explain + '<br>主要包括:' + content.newslist[0].contain + '<br>投放提示:' +content.newslist[0].tip
        return response
    } else {
		 console.log('查询失败提示:', content.msg)
        return '暂时还没找到这个垃圾呢'
    }
}


 在根目录下的index.js增加以下判断:

if(content.substr(0, 1) == "?") {
			let roomContent = content.replace('?','')
			 replyRoom = await superagent.getLajifenlei(roomContent)
			await delay(2000)
            await room.say('@' + contact.name() + '  ' + replyRoom)		
		}


相关链接:

天行数据上线垃圾分类接口及示例小程序

https://wenda.tianapi.com/article/96 

垃圾分类API接口


本站所有文章均为天行博客原创,转载请注明来源及出处!

作者:宇天行 (关于我

本文首发地址:https://www.huceo.com/post/496.html

或许您还会喜欢这些文章:

Tags: 作者:宇天行 | 分类:开发技术 | 评论:4 | 浏览:122022