npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

qcloud-scf-handlers

v1.2.5

Published

腾讯云云函数(SCF)的入口函数,可以来简化企业微信的消息处理代码

Downloads

4

Readme

qcloud-scf-handlers

一般情况下,当我们对微信消息进行接收处理时,会用到“云函数+API网关”的架构。此时,我们需要定义SCF中的main_handler函数。qc-scf-handlers中定义了一些函数作为预定义的main_handler

安装

npm i qcloud-scf-handlers

API

wecomHttpHandler([methodHandlers, options])

wecomHttpHandler 定义了一个一般的处理企业消息的HTTP处理程序,默认对GETPOST请求进行处置,而对其他类型的请求则直接返回200.

返回值

返回一个handler(event, context)函数作为main_handler

参数

  • methodHandlers 可选,针对不同HTTP请求的处理程序,默认不做任何处理直接返回200。
    • get(queryString, options),可选,默认进行服务器验证。
      • queryString 查询字符串
      • options 企业微信相关参数
    • post(body, options) 对接收到的消息进行处理,默认不做任何处理,直接返回200
  • options 可选,企业微信相关参数,默认由环境变量中读取。具体参见wecom-common

示例

exports.main_handler = async (event, context) => {
  // 腾讯云SCF使用CommonJS架构,因此只能使用import()加载包
  const { wecomHttpHandler } = await import('qcloud-scf-handlers');

  // 读取企业微信参数
  const { 运维日志appCfg } = await import('./utils.mjs');

  // 自定义的POST处理函数
  const { post } = await import('./http-method-dispatcher.mjs');
  const handler = wecomHttpHandler({
    post,
  }, 运维日志appCfg);
  return handler(event, context);
};

wecomMessageHttpHandler([msgTypeHandlers = {}, options = {}])

wecomMessageHttpHandlerwecomHttpHandler的基础上更进一步,根据企业微信发送的消息的类型(例如eventtext等)进行了处理。

返回值

返回一个handler(event, context)函数作为main_handler

参数

  • msgTypeHandlers 可选,针对不同的MsgType进行处理,默认不做任何处理,直接返回200
    • 消息类型(message) 处理特定消息,默认不处理
      • message 消息体
  • options 可选,企业微信相关参数,默认由环境变量中读取。至少应该包括:
    • encoding_aes_key 用户解密接收到的消息。具体参见wecom-common

示例

exports.main_handler = async (event/* , context */) => {
  const { wecomMessageHttpHandler } = await import('qcloud-scf-handlers');
  const { 运维日志appCfg } = await import('./utils.mjs');
  const msgTypeHandlers = await import('./msg-type-dispatcher.mjs');
  const handler = wecomMessageHttpHandler({
    event: msgTypeHandlers.event,
  }, 运维日志appCfg);
  return handler(event);
};