retailcrm / mg-bot-api-client-js

JS client for MG Bot API
MIT License
2 stars 4 forks source link

TypeError: clients[currentVersion] is not a constructor #14

Closed igorfltv closed 3 years ago

igorfltv commented 3 years ago

Getting Error after executing code from MD:

/////////////////////////////////////////////////// `const MgBotApiClient = require('mg-api-client')

const api = new MgBotApiClient({ host: 'xxxxxxx', token: 'xxxxxxx', apiVersion: 'v5' // optional }).client;

api.getUsers() .then(function (users) { console.log(users); }) .catch(function (e) { console.log(e); });`

/////////////////////////////////////// Error: const api = new MgBotApiClient this._client = new clients[currentVersion](new Request(options)); TypeError: clients[currentVersion] is not a constructor at new MgBotApiClient (C:\Users\igora\Git\RetailCRM\node_modules\mg-api-client\dist\index.js:875:22)

Environment: Win10, Node 14.17.4

iyzoer commented 3 years ago

You can omit the API version, since at the moment there is only one - v1. You may have confused the bot API with the RetailCRM API

igorfltv commented 3 years ago

API version was omited. We get this error now. api object was created successfuly after passing url+token for the bot.

const wsData = api.getWebsocketData([MgBotApiClient.types().wsMessageNew]);

TypeError: MgBotApiClient.types is not a function

We are trying WS example from GitHub page.

Neur0toxine commented 3 years ago

Did you import the library as per the instructions? Everything works fine for me:

const MgBotApiClient = require('mg-api-client');

const api = new MgBotApiClient({
    host: 'bot uri',
    token: 'bot token'
}).client;
const wsData = api.getWebsocketData([MgBotApiClient.types().wsMessageNew]);

console.log(wsData);

Please note that with ES6 imports the code will be somewhat different:

import MgBotApiClient, { types } from 'mg-api-client';

const api = new MgBotApiClient({
    host: 'bot uri',
    token: 'bot token'
}).client;
const wsData = api.getWebsocketData([types().wsMessageNew]);

console.log(wsData);

Feel free to provide a full code sample if the problem persists. The environment details (Node version, library version, etc) may also help.