0

My project uses the botkit-middleware-watson to talk to IBM Watson. Now I need to make a mock server for this Watson service.

This is just one line of code which calls Watson's API.

await watsonMiddleware.sendToWatsonAsync(bot, msg, null);

My question is, how can I intercept the API call and re-direct the call to my Watson Mock-Server?

Franva
  • 6,565
  • 23
  • 79
  • 144
  • Do you want to replace Watson Assistant by your mock server or just have the additional call? – data_henrik Aug 21 '19 at 06:52
  • @data_henrik I just need to have an end-2-end test which does not reply on the real Watson service. Not sure whether is it achievable? – Franva Aug 21 '19 at 07:22
  • That Watson botkit is just a plugin for an older version of botkit.ai (before it was bought). https://botkit.ai/docs/v0/middleware.html – data_henrik Aug 21 '19 at 07:56
  • hi @data_henrik thanks for your reply. I just just figured it out that I just need to provide some mock responses and that will be enough. – Franva Aug 26 '19 at 01:44

1 Answers1

1

botkit-middleware-watson examples like this one show how WatsonMiddleware can be configured:

const WatsonMiddleware = require('botkit-middleware-watson').WatsonMiddleware;

const middleware = new WatsonMiddleware({
  iam_apikey: process.env.ASSISTANT_IAM_APIKEY,
  workspace_id: process.env.WORKSPACE_ID,
  url: process.env.ASSISTANT_URL || 'https://gateway.watsonplatform.net/assistant/api',
  version: '2018-07-10'
});

...where ASSISTANT_URL is set in .env. This seems to be a place where to configure the URL of the mock server/simulator.

Another option could be for botkit to call the simulator as HTTP proxy, if the simulator you are using supports running as HTTP proxy.

apisim
  • 4,036
  • 1
  • 10
  • 16