2020var express = require ( 'express' ) ; // app server
2121var bodyParser = require ( 'body-parser' ) ; // parser for post requests
2222var AssistantV2 = require ( 'ibm-watson/assistant/v2' ) ; // watson sdk
23+ const { IamAuthenticator } = require ( 'ibm-watson/auth' ) ;
2324
2425var app = express ( ) ;
2526
@@ -30,13 +31,17 @@ app.use(bodyParser.json());
3031// Create the service wrapper
3132
3233var assistant = new AssistantV2 ( {
33- version : '2019-02-28'
34+ version : '2019-02-28' ,
35+ authenticator : new IamAuthenticator ( {
36+ apikey : process . env . ASSISTANT_IAM_APIKEY
37+ } ) ,
38+ url : process . env . ASSISTANT_IAM_URL ,
3439} ) ;
3540
3641
3742// Endpoint to be call from the client side
3843app . post ( '/api/message' , function ( req , res ) {
39- var assistantId = process . env . ASSISTANT_ID || '<assistant-id>' ;
44+ let assistantId = process . env . ASSISTANT_ID || '<assistant-id>' ;
4045 if ( ! assistantId || assistantId === '<assistant-id>' ) {
4146 return res . json ( {
4247 'output' : {
@@ -52,8 +57,8 @@ app.post('/api/message', function (req, res) {
5257 }
5358
5459 var payload = {
55- assistant_id : assistantId ,
56- session_id : req . body . session_id ,
60+ assistantId : assistantId ,
61+ sessionId : req . body . session_id ,
5762 input : {
5863 message_type : 'text' ,
5964 text : textIn
@@ -73,7 +78,7 @@ app.post('/api/message', function (req, res) {
7378
7479app . get ( '/api/session' , function ( req , res ) {
7580 assistant . createSession ( {
76- assistant_id : process . env . ASSISTANT_ID || '{assistant_id}' ,
81+ assistantId : process . env . ASSISTANT_ID || '{assistant_id}' ,
7782 } , function ( error , response ) {
7883 if ( error ) {
7984 return res . send ( error ) ;
0 commit comments