New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

koa-wechat

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-wechat

wechat offical account API middleware for koajs

0.1.3
latest
Source
npm
Version published
Weekly downloads
11
37.5%
Maintainers
1
Weekly downloads
 
Created
Source

koa-wechat

Wechat Official Account API (微信公众平台API) middleware for koajs

Usage

var app = require('koa')()
var wechat = require('koa-wechat')

app.use(wechat({ token: 'wechat_token' }))

To use this with weixin-robot:

// Get the robot
app.use(function *(next) {
  var media_id = this.path.split('/')[1]
  if (!media_id) {
    this.throw(404)
  }
  var webot = yield Webot.get(media_id)
  if (!webot) {
    this.throw(404)
  }
  this.webot = webot
  this.wx_token = webot.wx_token
  yield next
})

app.use(wechat())
app.use(session({ store: redisc('webot:session:') }))

// do the reply
app.use(function *(next) {
  var info = this.req.body
  info.session = this.session
  this.body = yield this.webot.reply(info)
  yield next
})

// an empty handler to prevent any following middlewares
app.use(wechat.close())

options.token

Token assigned to wechat API.

options.tokenProp

Find the token from a ctx property, i.e., this[tokenProp]

options.checksig

Whether we need to check signature or not, default to true.

options.session

By default, koa-wechat will set a this.sessionId to identify (a offical account + a subscriber) as an unique session. Then you can safely use koa-session middleware to save an subscriber's session. You can set options.session to false to disable this behavior.

Keywords

koa

FAQs

Package last updated on 08 Jul 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts