All Projects → doterlin → Wechat Robot

doterlin / Wechat Robot

Licence: mit
✅ js微信聊天机器人(使用个人账号,非公众号) Wechat chat robot write by js.

Programming Languages

javascript
184084 projects - #8 most used programming language
js
455 projects

Projects that are alternatives of or similar to Wechat Robot

Xiaofendui
薅羊毛小分队(第一时间尽知羊毛)- 微信机器人即时推送
Stars: ✭ 356 (+105.78%)
Mutual labels:  robot, wechat
Chatapi Wechat
Java版本微信聊天接口,使用网页微信API,让你能够开发自己的微信聊天机器人
Stars: ✭ 207 (+19.65%)
Mutual labels:  robot, wechat
Vbot
💬The best wechat robot base on web api!
Stars: ✭ 3,301 (+1808.09%)
Mutual labels:  robot, wechat
Swoole Bot
基于swoole实现的微信机器人,依赖vbot和微信网页版的功能,帮助管理微信群/聊天/踢人等
Stars: ✭ 404 (+133.53%)
Mutual labels:  robot, wechat
Itchat
A complete and graceful API for Wechat. 微信个人号接口、微信机器人及命令行微信,三十行即可自定义个人号机器人。
Stars: ✭ 21,935 (+12579.19%)
Mutual labels:  robot, wechat
Wechat
java微信客户端
Stars: ✭ 109 (-36.99%)
Mutual labels:  robot, wechat
Wechat Go
go version wechat web api and message framework for building wechat robot
Stars: ✭ 1,381 (+698.27%)
Mutual labels:  robot, wechat
Alarmrobot
微信机器人 提醒机器人 python机器人 微信pc机器人
Stars: ✭ 110 (-36.42%)
Mutual labels:  robot, wechat
Omi
Front End Cross-Frameworks Framework - 前端跨框架跨平台框架
Stars: ✭ 12,153 (+6924.86%)
Mutual labels:  wechat
Open manipulator
OpenManipulator for controlling in Gazebo and Moveit with ROS
Stars: ✭ 163 (-5.78%)
Mutual labels:  robot
Cleanupwechatzombiefans
auto.js脚本,Android自动化,清理微信僵尸粉
Stars: ✭ 155 (-10.4%)
Mutual labels:  wechat
Pythonrobotics
Python sample codes for robotics algorithms.
Stars: ✭ 13,934 (+7954.34%)
Mutual labels:  robot
Jenkins Zh
Jenkins 中文社区网站源码
Stars: ✭ 165 (-4.62%)
Mutual labels:  wechat
We Cropper
微信小程序图片裁剪工具
Stars: ✭ 1,972 (+1039.88%)
Mutual labels:  wechat
Rcc
RCC is a set of tooling that allows you to create, manage, and distribute Python-based self-contained automation packages - or 'robots' as we call them.
Stars: ✭ 168 (-2.89%)
Mutual labels:  robot
Robot
Simple library for controlling a raspberry pi based robot
Stars: ✭ 156 (-9.83%)
Mutual labels:  robot
Wechat Request
🚀⚡️基于Promise实现微信小程序http请求,轻便,小巧,api友好,功能丰富
Stars: ✭ 156 (-9.83%)
Mutual labels:  wechat
Abp.wechat
Abp 微信 SDK 模块,包含对微信小程序、公众号、企业微信、开放平台、第三方平台等相关接口封装。
Stars: ✭ 168 (-2.89%)
Mutual labels:  wechat
Imall
基于Laravel5.2,Vue.js1.0的微信商城,用于熟悉 Laravel、Vuejs、Webpack、Gulp 的结合使用,已不维护及更新。(1MB单核基础服务器,浏览请耐心等待图片加载...)
Stars: ✭ 168 (-2.89%)
Mutual labels:  wechat
Wechat Miniprogram Webar
A WeChat MiniProgram Image AR using computer vision. No OpenCV, No Deep Learning. Only JavaScript Implementation.
Stars: ✭ 163 (-5.78%)
Mutual labels:  wechat

Travis MIT copyRight

基于phantomjs和web端微信开发的聊天机器人。使用的微信账号(即充当机器人的账号)为个人账号,可自定义指令。

效果

可以指定一个微信账号:

撩妹

自定义指令不会交给AI处理:

自定义指令

独乐乐不如众乐乐,可以指定到群聊上:

微信群

在后台程序查看log:

命令行输出

使用场景

  • 微信智能回复,监控,统计等
  • 便捷查询
  • 娱(liao)乐(mei)

如何使用

1.安装环境

下载源码:

git clone https://github.com/doterlin/wechat-robot.git

安装以下环境:

1.node.js

2.phantomjs

3.casperjs

2.配置

找到并配置好/config/const.js

//机器人名字
var ROBOT_NAME = "小强";

module.exports = {
    //微信web版地址
    'URL'          : 'https://wx.qq.com/',

    //机器人名字
    'ROBOT_NAME'   : ROBOT_NAME,
    
    //图灵机器人apiKey和api地址
    //AI部分使用的是第三方机器人图灵(http://www.tuling123.com/)
    //这里只是示例,请大家自行到图灵官网注册并替换掉apikey免费版限5000次调用/天。有条件的同学可以付费支持下好产品
    'TURING_APIKEY': '99fecec3424d416898b91b0998e2b26a',
    'TURING_URL'   : 'http://www.tuling123.com/openapi/api',

    //锁定的微信号备注,注意是备注;如果是群聊则填群聊名称即可。
    //填写的名称请预先在手机微信上搜索确认搜索结果是否出现在第一个
    'TARGET_NICK'  : '二十投小分队',

    //启动时打招呼消息
    'HELLO_WORLD'  : '[闪电]' + ROBOT_NAME + '[闪电]已启动...',

}

3.运行和登录微信

安装依赖和运行命令:

npm install
casperjs index.js

如果提示python找不到之类的话请安装一下python并保证其能运行在全局

扫码登录微信 运行后看到如下提示时则扫一下弹出来的二维码:

正在加载二维码...
已保存二维码,路径:"static/img/qr.jpg".
正在使用默认软件打开二维码,请用手机微信扫一扫确认登录 (若没有请手动打开)

请在一分钟内使用手机扫码并确认登录。出现登录成功发送欢迎语提示后即可。这样就完成了使用步骤。下面的章节是介绍如何去扩展功能。

指令和AI

在这之前你可能需要两个方法:

message.send()

//路径:src/utils/message.js
//回复消息的方法message.send
//使用如:
var message = require('/src/utils/message');
...
casper.then(function(){
   message.send(this, '你好');
})

ajax() / ajax.get() / ajax.post() / ajax.getJSON()

//路径:src/utils/ajax.js
//在聊天器调ajax的方法
//使用如:
var  ajax= require('/src/utils/ajax');
...
casper.then(function(){
   ajax(this, "http://example.com/getInfo", 'get', {uid: 123}, function(res){
        console.log(JSON.stringify(res));
    });
  
   //或者
   ajax.get(this, "http://example.com/getInfo", {uid: 123}, function(res){
        console.log(JSON.stringify(res));
    });

   //jsonp
   ajax.getJSON(this, "http://example.com/getInfo?calback=?", {uid: 123}, function(res){
        console.log(JSON.stringify(res));
   });
})

你可以根据需要按以下方面扩充机器人的功能:

编写指令
//你可以写一些指令而不是交给AI处理
//指令分为精确匹配指令和模糊匹配指令

//-------------------------------------------------------------------
//精确匹配
//精确指令在`/src/directive/exact.js`下编写。
//key是指令名称,值是一个方法,接受参数msgContent(用户发送的消息)和casperIns(casper实例),如:
//当对方发送'关闭'指令时程序提示并退出。
module.exports = {
    '关闭': function (msgContent, casperIns) {
        message.send(casperIns, '[玫瑰]感谢您的使用[玫瑰]\n\r([闪电]需要开启请在控制台启动程序[闪电])');
        casperIns.echo('微信发出关闭口令,程序退出。')
        return casperIns.exit();
    }
}

//-------------------------------------------------------------------
//模糊匹配
//模糊匹配指令在`/src/directive/fuzzy.js`下编写。
//接收参数前两个同精确指令,第三个是当前的正则表达式;
//指令可单独防在src/directive/explain下方便维护,如weather.js:
//匹配'地名 + 天气',调用天气api
var weather = require('./explain/weather');
module.exports = {
    '/天气/g': weather 
}
//weather.js实现如下:
var ajax = require('../../utils/ajax');
var message = require('../../utils/message');

var formatWeather = function(local, weather) {
    //此方法对返回的json格式化,详情请查看源码
}

var weather = function(msgContent, casperIns, regex) {
    var local = msgContent.replace(/ |天气/, '');
    var resource = 'http://wthrcdn.etouch.cn/weather_mini?city=' + encodeURIComponent(local);

    ajax.get(casperIns, resource, {}, function(res){
        var weather = JSON.parse(res);
        if (weather.status == 1000) {
            message.send(casperIns, formatWeather(local, weather));
        } else {
            message.send(casperIns, '未查找到相关天气信息。请尝试输入格式如"广州天气"。')
        }
    });
   
}
module.exports = weather;
//-------------------------------------------------------------------
完善AI

这个我目前也没研究。

调试

调试代码时可将capserjs配置选像中的logLevel字段设为info将会显示更多phantomjslog,更多配置请移步casperjs文档。

//路径:config/casper.js
module.exports =  {
    clientScripts:  [
        'static/js/jquery.js'
    ],
    pageSettings: {
        loadImages: true,
        userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.14 Safari/537.36',
    },
    logLevel: "info", //here
    viewportSize: {width: 1300, height: 900},
    verbose: true,
    waitTimeout: 1000 * 60 * 60 * 24 * 365,
    onWaitTimeout: function(){
        console.log( 'waitFor*方法超时...' )
    }
}

另外,在执行各个步骤时会把浏览器截图保存到/static/img,方便查看浏览器渲染情况。比如每获取到一条新消息时会截图并覆盖为lastNewMsgContent.png

欢迎二次开发提PR,共同完善项目!

版本预告

下一版本更新但不限于以下内容:

1.支持绑定多个微信帐号
2.UI化控制台(node.js web同步命令log及部分操作)
3.支持图片识别和回复(如斗图)
4.更多实用指令

MIT License

Copyright (c) 2020 doterlin

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].