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

wechaty-weixin-openai

v0.2.10

Published

Weixin OpenAI Plugin for Wechaty

Downloads

122

Readme

wechaty-weixin-openai

NPM Version NPM

Weixin OpenAI is a cloud-based Natural Language Processing (NLP) service that easily creates a natural conversational layer over your data.

Wechaty Weixin OpenAI plugin enables your bot with Weixin OpenAI skills

Wechaty Plugin Weixin OpenAI

Wechaty Plugin Weixin OpenAI Powered by Wechaty TypeScript

Introduction

Wechaty Weixin OpenAI Plugin helps you to answer questions in WeChat with the power of https://openai.weixin.qq.com.

Weixin OpenAI Homepage

Requirements

  1. Node.js v12+
  2. Wechaty v0.40+
  3. This Weixin OpenAI Plugin
  4. Registration of Weixin OpenAI platform
  5. A bot in Weixin OpenAI platform

Usage

import { Message, Wechaty }  from 'wechaty'
import {
  WechatyWeixinOpenAI,
  AIBotRequestResponse,
  SentimentData
}                            from 'wechaty-weixin-openai'

const config = {
  mention: true, // default true: require at the bot in room.
  room: true,
  contact: true, // enable direct message.

  /**
   * Weixin OpenAI config
   */
  token: 'your-valuable-token',
  encodingAESKey: 'very-secret-encoding-key',

  /**
   * Decide whether the `preAnswerHook` function have the
   * `sentiment` argument passed.
   */
  includeSentiment: true,

  /**
   * No answer from Weixin OpenAI will call the below callback function
   */
  noAnswerHook: (message: Message) => { console.log(`No Answer Message: ${message}`) }

  /**
   * Will be called before the answer really replied by the bot
   * In the hook function, the answer that going to be answered
   * and sentiment data will be passed into the function
   *
   * If the function returns false, this function will block
   * further process of the message. With this, you can get the
   * answer from the Weixin OpenAI and decide you want to use
   * it with your own logic
   */
  preAnswerHook: (
    message: Message,
    answer: AIBotRequestResponse,
    sentiment?: SentimentData,
  ) => {
    console.log(`PreAnswerHook() with message: ${message}, answer: ${answer} and sentiment: ${sentiment}`)
  }
}

const WeixinOpenAIPlugin = WechatyWeixinOpenAI(config)

const wechaty = new Wechaty()
wechaty.use(WeixinOpenAIPlugin)

1 Configure Weixin OpenAI

  1. config.token: Token for Weixin OpenAI
  2. config.encodingAESKey: Encoding AES key for Weixin OpenAI

2 Language of Questions

  1. config.language: If set to a language ('chinese', 'english', etc), then the plugin will only reply message text in that specified language. (default: match all languages)

3 Matchers & Skipper

  1. config.contact: Whether to allow direct message to be sync with ticket reply. false to deny all, true for allow all; Supports contact id(string) and contact name(RegExp). You can also mix them in array.
  2. config.room: The room id of your service WeChat room.
  3. config.skipMessage: If set it to string or RegExp, then the message text that match the config will not be processed by the plugin. Array supported.

4 Hook functions

  1. config.noAnswerHook: This is an optional argument, if this function is defined, when Weixin OpenAI returns an answer that actually matched nothing, this function will be called, which allows you to do other logic when the Weixin OpenAI bot can not answer the question automatically for you, such as push your own contact card or create a room with the bot and you together.
  2. config.preAnswerHook: This hook function is called before the real answer action is taken. In this hook function, you can get the message and the answer returned from Weixin OpenAI. You can add your own logic to determine whether this message should be answered by Weixin OpenAI automatically or not. Returning false in the hook function will prevent further code to be executed.

5 NLP related functions

  1. config.includeSentiment: This will decide whether you want to append sentiment data analyzed by Weixin OpenAI into the preAnswerHook function.

Environment Variables

The following two environment variables will be used if the required information is not provided by the config.

1 WECHATY_WEIXIN_OPENAI_TOKEN

process.env.WECHATY_WEIXIN_OPENAI_TOKEN will be used if the config.token is not provided.

2 WECHATY_WEIXIN_OPENAI_ENCODING_AES_KEY

process.env.WECHATY_WEIXIN_OPENAI_ENCODING_AES_KEY will be used if the config.encodingAESKey is not provided.

History

master

v0.2 (Jun 29, 2020)

  1. Init code base from wechaty-plugin-qnamaker
  2. Weixin Open AI integration
  3. Add aibot api integration with Weixin OpenAI
  4. Add `noAnswer

Contributors

contributor contributor contributor contributor contributor contributor contributor contributor

Author

Yuan Gao (高原), CTO & Co-founder of Juzi.bot, <[email protected]>

Copyright & License

  • Code & Docs © 2020 Yuan Gao <[email protected]>
  • Code released under the Apache-2.0 License
  • Docs released under Creative Commons