
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
watson-assistant-for-wechat
Advanced tools
Helping developers building a chatbot for WeChat powered by Watson Assistant
Watson Assistant integration in WeChat for ExpressJS.
yarn install watson-assistant-for-wechat
OR
npm i watson-assistant-for-wechat
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);
}
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"
);
IBM Cloud IAM API Key, see IBM Cloud Documentation
The ID of the Watson Assistant instance.
Avaliable at Launch assistant -> Top Right (settings) -> API Details
The token set at WeChat server endpoint configuration, see WeChat Documentation
Default value 2020-02-05
Watson Assistant API version, see IBM Cloud Documentation
Default value https://api.us-south.assistant.watson.cloud.ibm.com
Watson Assistant API endpoint, see IBM Cloud Documentation
Default value locals.chat
The name of property under app
where to attach the chat
method
const { chat } = req.app.locals;
Default value message
The name of property under req
where to attach the incoming message from WeChat server
const { message } = req;
Default value user
The name of property under req
where to attach the ID of incoming WeChat user
const { user } = req;
>=12
cp .env.example .env
yarn install
yarn dev
FAQs
Helping developers building a chatbot for WeChat powered by Watson Assistant
The npm package watson-assistant-for-wechat receives a total of 1 weekly downloads. As such, watson-assistant-for-wechat popularity was classified as not popular.
We found that watson-assistant-for-wechat demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.