GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - dhso/hapi-wechat: Wechat plugin for hapi

BranchesTags
Open more actions menu

Latest commit

 

History

42 Commits
42 Commits

Folders and files

NameName
Last commit message
Last commit date
lib
lib
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
package.json
package.json
 
 

Repository files navigation

hapi-wechat

Wechat plugin for hapi

co-wechat-api

version: 3.8.1

https://github.com/node-webot/co-wechat-api

http://doxmate.cool/node-webot/co-wechat-api/api.html

install

npm install github:dhso/hapi-wechat

options

routerPath: '/wechat, required'
handlerPath: 'wechat/*.js', required'
appid: 'your appid, required',
appsecret: 'your appsecret, required'
token: 'your token, required'
encodingAESKey: 'your encodingAESKey, optional'

example

  • support type
['text', 'image', 'voice', 'video', 'location', 'link', 'subscribe', 'unsubscribe', 'click']
  • text handler
// /wechat/text.js

module.exports = async (inMsg, req, h) => {
    try {
        // wechat api send message
        let res = await h.wechat_api.sendText(inMsg.fromUsername, 'Hello world');
        console.log(res);
        // send common message
        return {
            content: inMsg.content
        }
    } catch (err) {
        // send error message
        return {
            content: err.message
        }
    }
};
  • subscribe handler
// /wechat/subscribe.js

module.exports = (inMsg, req, h) => {
    return {
        msgType: 'news',
        content: [
            {
                title: "欢迎关注ThinkApp",
                description: "这是本人测试用的订阅公众号,欢迎访问我的Oschina Git。",
                url: "https://gitee.com/dhso"
            }
        ]
    }
};
  • a tuling robot example
module.exports = async (inMsg, req, h) => {
    try {
        let reply, tuling = await h.axios.post('http://www.tuling123.com/openapi/api', {
            "key": "your key",
            "userid": inMsg.fromUsername,
            "info": inMsg.content
        });
        switch (tuling.data.code) {
            case 100000:
                reply = { 'content': tuling.data.text };
                break;
            case 200000:
                reply = {
                    'msgType': 'news',
                    'content': [{
                        'title': tuling.data.text,
                        'description': '请点击跳转到结果页面。',
                        'url': tuling.data.url
                    }]
                }
                break;
            case 302000:
                reply = {
                    'msgType': 'news',
                    'content': []
                }
                for (var item of tuling.data.list) {
                    if (reply.content.length >= 8) break;
                    reply.content.push({
                        'title': item.article,
                        'description': item.source,
                        'picurl': item.icon.indexOf('//') == 0 ? 'http:' + item.icon : item.icon,
                        'url': item.detailurl
                    });
                }
                break;
            case 308000:
                reply = {
                    'msgType': 'news',
                    'content': []
                }
                for (var item of tuling.data.list) {
                    if (reply.content.length >= 8) break;
                    reply.content.push({
                        'title': item.name,
                        'description': item.info,
                        'picurl': item.icon.indexOf('//') == 0 ? 'http:' + item.icon : item.icon,
                        'url': item.detailurl
                    });
                }
                break;
        }
        return reply;
    } catch (err) {
        return {
            content: err.message
        }
    }
};

About

Wechat plugin for hapi

Resources

Readme
MIT license
Activity

Stars

5 stars

Watchers

2 watching

Forks

4 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.