node-webot / co-wechat

Wechat for Koa
427 stars 91 forks source link

finish handler #1

Closed terry-fei closed 9 years ago

terry-fei commented 9 years ago
var app = require('koa')();
var wechat = require('../lib/wechat');

var config = {
  path: '/wx/api',
  token: 'feit'
};

app.use(wechat(config).all(function *() {
  console.log(this.weixin.Content);

}).text(function *() {
  this.body = this.weixin.Content;

}).middlewarify());

app.listen(3000, function () {
  console.log('wechat server start!');
});
terry-fei commented 9 years ago

朴大要是觉得这么设计可以的话我就进行下一步了 :)

terry-fei commented 9 years ago
var handle = function* (next) {
  // 中间件
};
app.use(mout('/path', wechat(config).middleware(handle)));

不用根据消息类型调用响应的方法吗?

JacksonTian commented 9 years ago

那个在handle里玩。

ktmud commented 9 years ago

这个模块用到的都是 koa 相关的API,叫 co-wechat 可能不太合适。

可惜 koa-wechat 被我用了,哈哈…… https://github.com/ktmud/koa-wechat/blob/master/index.js

terry-fei commented 9 years ago
var app = require('koa')();
var wechat = require('../lib/wechat');

app.use(wechat('feit').middleware(function *() {
  console.log(this.weixin.Content);
  this.body = 'nodejs';
}));

app.listen(3000);
terry-fei commented 9 years ago

all test passing, i will write readme tomorrow, if no problem with this branch please merge it:)

JacksonTian commented 9 years ago

+1