在上一往篇文章《Nodejs微信开发》中,微信后台能够正常的接收到客户端的消息,并能够简单的回复一条消息至客户端。

但我的目录是将微信与Bot Framework进行关联,那么肯定就有一些情况是Bot Framework是有多条消息,或是会回复图片消息的,这个时候只回复一条消息就无法满足我现在的需求了

可以看到在以下代码中,我使用wechat进行微信消息的接收,使用wechat-api对用户进行多次的回复,我就可以解决wechat只能对消息回复一次的问题

简单来说,wechat只负责接收到消息的回复,从bot framework提取到的消息需要通过wechat-api来进行发送

var wechat = require('wechat');
var wechatAPI = require('wechat-api'); //wechat config
var config = {
token: 'weixin',
appid: 'wx1434eed5268660c4',
encodingAESKey: 'ZEtViedarf49EUOCDeu45pqhkZhKPFBjSHI2DynP4vq',
checkSignature: true // 可选,默认为true。由于微信公众平台接口调试工具在明文模式下不发送签名,所以如要使用该测试工具,请将其设置为false
}; //创建wechat-api
var api = new wechatAPI(config.appid, '30a5f51682755652e6e02879757a0fb1'); var menu = {
"button": [
{
"type": "click",
"name": "WeChat Bot",
"key": "V1001_TODAY_MUSIC"
},
{
"name": "BotFramework",
"sub_button": [
{
"type": "view",
"name": "botframework",
"url": "https://dev.botframework.com/"
},
{
"type": "click",
"name": "赞一下我们",
"key": "V1001_GOOD"
}, {
"name": "发送位置",
"type": "location_select",
"key": "rselfmenu_2_0"
},]
}]
};
//删除菜单
api.removeMenu(function (err, result) {
if (err) {
logger.log('error', err);
}
logger.log('info', 'remove menu success');
}); //创建菜单
api.createMenu(menu, function (err, result) {
if (err) {
logger.log('error', err);
}
logger.log('info', 'create menu success');
}); app.use(express.query());
app.use('/wechat', wechat(config, wechat.text(function (message, req, res, next) {
//------------------------------------------------------------------------
var message = req.weixin;
logger.log("info", message); res.reply('Message Send To Bot Completed , Wait Response.'); api.sendText(message.FromUserName, 'this message from wechat-api', function (err, result) {
if (err) {
logger.log('error', err);
}
logger.log('info', 'reply message success');
}); }).image(function (message, req, res, next) {
var message = req.weixin;
logger.log("info", message); res.reply('功能开发中');
}).voice(function (message, req, res, next) {
var message = req.weixin;
logger.log("info", message); res.reply('功能开发中');
}).video(function (message, req, res, next) {
var message = req.weixin;
logger.log("info", message); res.reply('功能开发中');
}).location(function (message, req, res, next) {
var message = req.weixin;
logger.log("info", message); res.reply('功能开发中');
}).link(function (message, req, res, next) {
var message = req.weixin;
logger.log("info", message); res.reply('功能开发中');
}).event(function (message, req, res, next) {
var message = req.weixin;
logger.log("info", message); res.reply('感谢你的关注,你也可以在nodejs npm中查看wechat和wechat-api'); }).device_text(function (message, req, res, next) {
var message = req.weixin;
logger.log("info", message); res.reply('功能开发中');
}).device_event(function (message, req, res, next) {
if (message.Event === 'subscribe' || message.Event === 'unsubscribe') {
var message = req.weixin;
logger.log("info", message); res.reply("功能开发中");
} else {
var message = req.weixin;
logger.log("info", message); res.reply('功能开发中');
}
})));

参考:https://www.npmjs.com/package/wechat-api

https://www.npmjs.com/package/wechat

http://mp.weixin.qq.com/wiki/16/52e198333f5c127ddd5c45e875191b14.html

Nodejs微信开发使用wechat-api回复多条消息的更多相关文章

  1. Nodejs微信开发

    因为使用了Bot Framework开发了一个小功能,它目前支持了Skype\Teams\Slack等,但在国内来讲,微信还是一个比较流行的软件,所以需要接上微信 原来开发Bot的时候使用的是.Net ...

  2. 【微信开发】常用 api

    [微信开发]api 一. 开发文档 二. 调试工具 三. api 1. 获取 token - https://api.weixin.qq.com/cgi-bin/token?grant_type=cl ...

  3. 微信.NET 微信开发 自己主动内容回复 ASP.NET C#代码

    微信开发中,首先遇到的问题就是处理怎样接收和响应用户消息 , 本文将向大家介绍一下方法和关键的代码. 本文使用的接口库是  :https://github.com/chendong152/Weixin ...

  4. nodejs微信开发获取token,ticket-1

    /* jshint -W079 */ /* jshint -W020 */ "use strict"; var _ = require("lodash"); v ...

  5. 解析nodejs微信开发-2获取ticket

    获取ticket是需要拼接url,url中需要获得的tocken 1.先判断有无tocken:若有则拼接url: 2.请求url: a.处理回调数据,注意时间戳和签名处理方式,此两项并未存到ticke ...

  6. java微信开发(wechat4j)——发送客服消息

    微信支持主动发送客服消息.如果你要实现此功能,需要使用CustomerMsg类. 获得access_token access_token请求之后有一个过期时间,微信平台建议你使用一个中控服务器来定时刷 ...

  7. java微信开发API解析(二)-获取消息和回复消息

    java微信开发API解析(二)-获取消息和回复消息 说明 * 本演示样例依据微信开发文档:http://mp.weixin.qq.com/wiki/home/index.html最新版(4/3/20 ...

  8. nodejs微信公众号快速开发|自定义关键字回复

    一点说明: nodejs 微信api 扩展,集成大部分功能. 案例 https://github.com/leiroc/node-wxeasy-example 上传example中文件到服务器 ,然后 ...

  9. 记微信开发(有道翻译api)

    记微信开发(有道翻译api) 记微信开发(有道翻译api) 效果: 有道翻译api申请: 地址:http://fanyi.youdao.com/openapi code: <?php/** * ...

随机推荐

  1. RadioGroup 的使用

    //获取 RadioGroup 项目名称 procedure TForm1.RadioGroup1Click(Sender: TObject); begin   Text := RadioGroup1 ...

  2. Delphi中动态创建窗体有四种方式

    Delphi中动态创建窗体有四种方式,最好的方式如下: 比如在第一个窗体中调用每二个,主为第一个,第二个设为动态创建 Uses Unit2; //引用单元文件 procedure TForm1.But ...

  3. Docker实战系列一:初识Docker for Windows

    windows下安装Docker官网教程Install Docker for Windows Docker配置官网教程Get started with Docker for Windows

  4. Android逆向之旅---爆破一款资讯类应用「最右」防抓包策略原理分析

    一.逆向分析 首先感谢王同学提供的样本,因为王同学那天找到我咨询我说有一个应用Fiddler抓包失败,其实对于这类问题,我一般都会这么回答:第一你是否安装Fiddler证书了,他说他安装了.第二你是否 ...

  5. ext大法好啊

    http://www.cnblogs.com/keshuqi/p/6257895.html

  6. Angular 遍历循环数组

    var app = angular.module('Mywind',['ui.router']) app.controller('Myautumn',function($scope,$http,$fi ...

  7. webpack 3.8 使用 extract-text-webpack-plugin 3.0 抽取css失败:You may need an appropriate loader to handle this file type.

    webpack 3.8.1 使用 extract-text-webpack-plugin 3.0.2 抽取css时失败,报错: ERROR in ./src/static/style/localTim ...

  8. HNOI2002 营业额统计 [Splay]

    题目描述 Tiger最近被公司升任为营业部经理,他上任后接受公司交给的第一项任务便是统计并分析公司成立以来的营业情况. Tiger拿出了公司的账本,账本上记录了公司成立以来每天的营业额.分析营业情况是 ...

  9. hdu 1520Anniversary party 树形dp入门

    There is going to be a party to celebrate the 80-th Anniversary of the Ural State University. The Un ...

  10. mysql的对象

      mysql 常见的数据对象有哪些: DataBase/Schema Table Index View/Trigger/Function/Procedure   多Database用途: 业务的隔离 ...