message()

in lib/wit.js [21:52]


  message(q, context, n) {
    if (typeof q !== 'string') {
      throw new Error('Please provide a text input (string).');
    }

    const {apiVersion, headers, logger, proxy, witURL} = this.config;

    const params = {
      q,
      v: apiVersion,
    };

    if (typeof context === 'object') {
      params.context = JSON.stringify(context);
    }

    if (typeof n === 'number') {
      params.n = JSON.stringify(n);
    }

    const method = 'GET';
    const fullURL = witURL + '/message?' + encodeURIParams(params);
    logger.debug(method, fullURL);

    return fetch(fullURL, {
      method,
      headers,
      proxy,
    })
      .then(response => Promise.all([response.json(), response.status]))
      .then(makeWitResponseHandler(logger, 'message'));
  }