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

watson-assistant-for-wechat

v1.0.2

Published

Helping developers building a chatbot for WeChat powered by Watson Assistant

Downloads

7

Readme

Watson Assistant for WeChat

codecov

Watson Assistant integration in WeChat for ExpressJS.

Usage

Install

yarn install watson-assistant-for-wechat

OR

npm i watson-assistant-for-wechat

Example

Detail example is avaliable at app.js.

const {wechatWatsonAssistant} = require('watson-assistant-for-wechat');

// Initialize the applicatoin, and mount the endpoint at `/watson`
wechatWatsonAssistant(app, config, '/watson');

app.post('/watson', async (req, res) => {
	const {user, message} = req;
	const {chat} = req.app.locals;
  const storage = req.sessionStore;

  // Retrive sessionId of current WeChat user
  const sessionId = await getSessionId();

  // Post incoming text to Watson Assistant
  const {result: assistantResponse} = await chat(
    {message_type: 'text', text: message.Content},
    sessionId,
    setSessionId
  );

  // Generate response to WeChat server
  const response = reply.text(
    message.ToUserName,
    message.FromUserName,
    assistantResponse.output.generic[0].text
  );
  res.set('Content-Type', 'text/xml');
  res.send(response);
}

Configuration

Below is a list of avaliable configuration.

// Initialize the applicatoin, and mount the endpoint at `/watson`
wechatWatsonAssistant(
  app,
  {
    apiKey: process.env.IBM_CLOUD_IAM_KEY,
    assistantId: process.env.IBM_WATSON_ASSISTANT_ID,
    wechatToken: process.env.WECHAT_TOKEN,
    version: "2020-02-05",
    url: "https://api.us-south.assistant.watson.cloud.ibm.com",
    chatRequestProperty: "locals.chat",
    messageRequestProperty: "message",
    userRequestProperty: "user"
  },
  "/watson"
);

Options

apiKey (required)

IBM Cloud IAM API Key, see IBM Cloud Documentation

assistantId (required)

The ID of the Watson Assistant instance.

Avaliable at Launch assistant -> Top Right (settings) -> API Details

wechatToken (required)

The token set at WeChat server endpoint configuration, see WeChat Documentation

version

Default value 2020-02-05

Watson Assistant API version, see IBM Cloud Documentation

url

Default value https://api.us-south.assistant.watson.cloud.ibm.com

Watson Assistant API endpoint, see IBM Cloud Documentation

chatRequestProperty

Default value locals.chat

The name of property under app where to attach the chat method

const { chat } = req.app.locals;
messageRequestProperty

Default value message

The name of property under req where to attach the incoming message from WeChat server

const { message } = req;
userRequestProperty

Default value user

The name of property under req where to attach the ID of incoming WeChat user

const { user } = req;

Development

Require

  • NodeJS: >=12
  • Yarn

Setup

  • cp .env.example .env
  • yarn install
  • yarn dev

Author

  • IBM Cognitive Class, IBM Digital Business Group