Giter VIP home page Giter VIP logo

webot-cli's Introduction

webot-cli

Command line interface for weixin-robot.

npm install webot-cli -g

Commands

  Usage: webot <command> [options]

  Options:

    -h, --help     output usage information
    -V, --version  output the version number

  Commands:

    send [image|text|loc|..]   send a message to test host
    menu [create|delete|get]   manipulate wechat menu
    help [command]             view help info for specified command

Use webot help for more details.

发送测试消息

webot help send

微信自定义菜单

webot help menu

需要一个 json 文件保存 access_token 等配置信息(默认是当前目录的 wx_config.json)。 为安全起见,建议你只在本地使用此文件,不要把它放到代码仓库中。

{
  "appid": "abcedfe123456",
  "secret": "abcdefghijklmn1234567890"
}

创建或修改

按照微信文档中的[请求示例][1],新建一个 json 文件(如menu.json),然后利用 stdin 传入 webot menu create 命令:

文件 menu.json 的内容:

 {
     "button":[
     {  
          "type":"click",
          "name":"今日歌曲",
          "key":"V1001_TODAY_MUSIC"
      },
      {
           "type":"click",
           "name":"歌手简介",
           "key":"V1001_TODAY_SINGER"
      },
      {
           "name":"菜单",
           "sub_button":[
            {
               "type":"click",
               "name":"hello word",
               "key":"V1001_HELLO_WORLD"
            },
            {
               "type":"click",
               "name":"赞一下我们",
               "key":"V1001_GOOD"
            }]
       }]
 }

执行命令:

webot menu create --config wx_config.json < menu.json

自定义菜单与 webot 的结合

发送文字消息或者触发点击事件都可以:

var reg_gequ = /(今日歌曲|today music)/i;

webot.set('today_music', {
  pattern: function(info) {
    return reg_gequ.test(info.text) || info.param.eventKey === 'V1001_TODAY_MUSIC';
  },
  handler: function(info, cb) {
    // 从你的数据库里查找今日歌曲
    cb(null, {
      type: 'music',
      musicUrl: 'http://xxxx...',
      hqMusicUrl: 'http://xxxx...'
    });
  },
});

LICENCE

(the MIT licence)

[1]:http://mp.weixin.qq.com/wiki/index.php?title=%E8%87%AA%E5%AE%9A%E4%B9%89%E8%8F%9C%E5%8D%95%E6%8E%A5%E5%8F%A3#.E8.8F.9C.E5.8D.95.E5.88.9B.E5.BB.BA)

webot-cli's People

Contributors

ktmud avatar

Watchers

star avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.