node-webot / weixin-robot Goto Github PK
View Code? Open in Web Editor NEW微信公共帐号自动回复机器人 A Node.js robot for wechat.
微信公共帐号自动回复机器人 A Node.js robot for wechat.
因为刚接触,所以很多东西不懂。
希望有哪个大大建个Q群大家交流交流,如果没有的话。我这边有个空的群。
3616268 欢迎大家。
2013年春节,最新的微信文档
如果消息设置不做回复(info.ended = true),微信服务器则会发送同样的消息3次。我如何避免让微信服务器重发消息?
@ktmud ,你好,我最近尝试了下你的weixin-robot和webot-douban-event,感觉非常爽,现在遇到一个问题请教一下:
在webot-douban-event中,rules/dialogs下边有很多的.yaml文件,我直接把文件夹复制过来了,然后尝试了一下,出现下边这种问题:
webot:robot:log define route: [jielong] +0ms
webot:robot:log require dialog file: /home/ymcdull/node_funny/webot-example/rules/dialogs/basic.yaml +3ms
/......./webot-example/rules/dialogs/basic.yaml:1
require, module, __filename, __dirname) { /^(都?有(哪些|什么)(好玩的)?)?活动[??!!]_$/:
^
SyntaxError: Unexpected token :
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module.load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at /home/ymcdull/node_funny/webot-example/node_modules/weixin-robot/node_modules/webot/lib/webot.js:216:11
at Array.forEach (native)
at Webot.dialog (/home/ymcdull/node_funny/webot-example/node_modules/weixin-robot/node_modules/webot/lib/webot.js:212:8)
at module.exports (/home/ymcdull/node_funny/webot-example/rules/dialogs/index.js:3:7)
npm ERR! weird error 8
npm ERR! not ok code 0
make: ** [start] 错误 1
貌似是.yaml中的问题,如果我在正则匹配或者字符串前后加上引号,这个错误就没有了,请教一下这是什么原因?有没有什么方法可以不用把所有的匹配都加上引号来排除这个问题?多谢
由于wechat包本身有带一些接口,我本来希望通过express做一个和微信对接以及一个微信代理接口。但是所有页面都是显示invalid signature。大致代码如下
app = express();
//All Requests return "invalid signature"
app.get('/media/', routes.media);
wechat.watch(app, { token: data.token, path: '/' });
wechat.set('welcome', {
pattern: function(info) {
return info.is('event') && info.param.event == 'subscribe';
},
handler: data.welcome
});
你好,我在服务器上安装调试您的程序,然后准备接入微信公众平台,我修改了监听地址和token,但管网说无法响应,服务器上的webot调试成功,求解,谢谢。
webot.set('voice', {
pattern: function(info) {
return info.is('voice');
},
handler: function(info) {
console.log(info.text);
console.log(info.param.recognition);
if (info.text) {
return info.text;
};
}
});
我的代码如上,发送语音消息之后,info.text,info.param.recognition均是空字符串
部署上微信号之后,有的时候是好的,能正常回复信息。
有的时候是204请求,无法接受到发送内容,不能正常回复信息。
请问有没有人知道这是怎么回事?
按照example中的,创建多个实例失败了...
我在文档中没有找到相关的信息。
是否能在handler里面使用异步事件, 异步事件里面需要调动handler callback里面的info. 不知道应该如何实现
function generate_req(one_row) { //factory函数
return function(info) {
urllib.request(one_row.content, { data: info.param }, function (err, data) {
if (err) {
console.log('callback error. ' + err.toString());
}
data = data.toString();
try {
data = JSON.parse(data);
} catch(e) {
console.log('callback JSON parse error. ' + e.toString());
}
//return data to function(info) here
return data;
});
};
}
目前我的第一条rule是基于用户是否启动会话从而判断是否由weixin-robot来回复,否的话,noReply = true。但是不知为何,程序总是会跳到下一条rule,而且这是info为空,导致程序崩溃。大致代码如下
wechat.set('SUPPORT', {
pattern: function(info) {
return info.session.chatUsers.indexOf(info.uid) !== -1;
},
handler: function(info) {
if( info.is('event') ) {
info.reply = 'Doing Stuff...';
} else {
eventEmitter.emit('userMessage', info.uid, info.text);
info.noReply = true; //这里就不应该继续跳下去
}
}
});
wechat.set('SERVICE_DELIVERY', {
pattern: function(info) {
return info.param.eventKey.toLowerCase() === 'service_delivery'; //这里崩溃了
},
handler: 'some reply'
});
现在我的理解是node监听的是3000端口,而微信后台url不能填写如222.26.155.22:3000之类的网址,那我是否应该通过反向代理将3000映射到80端口以便在微信后台添加222.26.155.22即可正确相应token? 我的理解是否正确?
使支持回复图文消息
结果所有请求都是invalid signature,还有“HTTP/1.1 401 Unauthorized”错误
是不是我Post消息中不含token信息造成的,但我看weixin接口中post消息不需要token啊?
rt,能做到这一点吗?需要根据不同的ip回复不同的信息
Content原文是[ {} ]
,这里不能直接String(json.Content)
请问example中的location是怎么使用了? 我在客户端发送什么能返回给我location
我使用包含的wechat包创建了带有链接的菜单。但是点击的时候没有跳转。查询菜单的时候看起来是对的。Log告诉我请求返回到了我的服务器这里由wechat包处理,因为没有匹配的rule,最后匹配失败。
代码生成的菜单大致是这样的
{ button:
[ { name: 'StuffParent', sub_button:
[ { key: 'FARM_LIST', type: 'click', name: 'StuffStuff' },
{ key: 'RESELLER_LIST', type: 'click', name: 'Stuff1' },
{ url: '"http://example.com"', type: 'view', name: 'Stuff2' },
{ key: 'EVENT_LIST', type: 'click', name: 'Stuff3' } ] } ] }
附加微信调试工具出的菜单截图
避免使用者混淆 weixin-robot 作为 npm module 的意义
关于Info对象:
ToUserName 开发者微信号 info.uid
FromUserName 发送方帐号(一个OpenID) info.sp sp means "service provider"
是不是反了?
ps 感谢,正在整合weixin-robot到我们的项目中。
看见@ktmud在一个小时前更新了实例,估计现在还在弄,我测试了下,无法跑起来哦。在app.js里使用了webot.watch来监听消息请求,之前是webot.monitor(app, 'your1weixin2token');我测试的时候,显示no method of "watch".
采用了wechat
的中间件,结果所有请求都是invalid signature
这个项目其实挺好的,不过微信公布的接口有更新,作者不同步更新了吗?比如微信支持回复音乐和视频之类~
还想问一个小问题:
文档中的:
4. set DEBUG=weixin.* (设置环境变量方可查看调试信息)
我在shell里做了,不起作用?请问是什么原因?我google这个debug模块的使用也找不到相关的使用介绍...
服务器和测试运行在同一个进程中,这样可以方便mock异常状况。 https://github.com/senchalabs/connect/tree/master/test
感觉 heroku 的门槛比 cloudfoundtry 低一些, node 社区也更习惯 heroku
@atian25 意下如何?
既然被转义了,为何不转成 date 对象?
wind.js 写出来的代码难以调试,而且有潜在的性能问题。不了解这套机制的人维护起来也比较困难
underscore 是浏览器端产物,服务器端大部分时候不需要用到
各种 type 判断可以使用原生代码,extend defaults 等 utils 方法可以自己 include
模版工具可以用 lodash-template 代替
cc @atian25
既然载入一个 yaml 模块只是 require('a.yaml')
那样简单,
就可以把是否使用 yaml 的决定权交还给用户。
请问如何实现example里的waits到routes的联动?
比如说 在 routes中 输入 ‘搜索500’ 联动到 waites中询问 ‘您是要搜索伍佰吗?’ 得到确定回复后 联动到routes中执行搜索。
使支持:
webot.image(function() {
// ...
}).location(function() {
// ...
}).event(function() {
// ...
});
现在我的菜单需要输出一些内容,然后依照用户的输入来判断回复。之前在使用wechat包的时候,直接测试
List.add('stuff', [
['回复{a}', '成功回复a']
['回复{b}', '成功回复b']
]);
var eventResponse = function (info, req, res, next) {
res.wait('stuff');
};
var wechatObj = wechat(mytoken, wechat.event(eventResponse).text(textResponse));
然后挂一个List在eventResponse里面执行。现在如果得到同样的结果呢?我只能通过webot.set调回一个str或者obj或者arr。如何在webot.set里面回复另外一个webot.set?
很多虚拟主机如nae, cloudfoundry都是不支持c++的类库的.
建议换为pure javascript的类库.
PS1: 本想写个类库的, 却发现仁兄把我想写的都写了....
PS2: 正在看waitor那块,因为想做的东西是有流程的,而不仅仅是一两个来回的问答
提供办法将繁体转换成简体消息。可以先用 iconv 搞搞,然后再试一下 opencc 。
运行您的example,修改了端口号和WX_TOKEN。部署到服务器上微信能成功调用。
我在本地做测试时候遇到了如下的问题。请问这个应该怎么解决 ?
nasaAir:bin nasa$ webot -t mytest
the text: hi
events.js:71
throw arguments[1]; // Unhandled 'error' event
^
Error: connect ECONNREFUSED
at errnoException (net.js:769:11)
at Object.afterConnect [as oncomplete] (net.js:760:19)
nasaAir:bin nasa$
已经成功在本地与appfog上配置,并且微信可以使用。
不过只用到了examples文件夹内的app.js rules.js support.js
外面的一些文件,比如index.js引用的lib文件夹下是用来干嘛的?
能举例说明下其他文件干嘛用的吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.