Giter Site home page Giter Site logo

Comments (7)

stevkan avatar stevkan commented on September 28, 2024

@orgads - I'll be taking a look at this and will attempt a repro. Just to verify, can you please tell me which version of botframework-directlinejs, axios, and Node you have installed?

from botframework-directlinejs.

orgads avatar orgads commented on September 28, 2024

Node 18, all the packages are latest. This is the dependencies part in package.json

{
  "dependencies": {
    "axios": "^1.2.2",
    "botframework-directlinejs": "^0.15.1",
    "xhr2": "^0.2.1"
  }
}

from botframework-directlinejs.

stevkan avatar stevkan commented on September 28, 2024

@orgads - I was able to repro the issue. I'm currently researching it to try and identify where the specific failure is occuring and how it can be fixed or if there is a possible workaround. I will keep you posted.

from botframework-directlinejs.

stevkan avatar stevkan commented on September 28, 2024

For reference, here are the results of my repro noted above.

I used the customer's code with the exception of the observables. For those, I copied the code from the BotFramework-DirectLineJS readme doc just to ensure I was using tested code.

const XMLHttpRequest = require( 'xhr2');
const WebSocket = require( 'ws');
global.XMLHttpRequest = XMLHttpRequest;
global.WebSocket = WebSocket;
const crypto = require( 'crypto');
const { DirectLineStreaming, ConnectionStatus } = require('botframework-directlinejs');
const axios = require( 'axios');

const botUrl = 'https://some.site.azurewebsites.net/.bot/v3/directline';
const userId = crypto.randomUUID();
const username = `dl_ac_test-${userId.substring(0, userId.indexOf('-'))}`;

const botSecret = 'yEeoO.....FjSHI';

async function main() {
  const data = { user: { id: username } };
  const token = (
    await axios.post('tokens/generate', data, {
      baseURL: botUrl,
      headers: { Authorization: `Bearer ${botSecret}` },
    })
  ).data;
  
  console.log('TOKEN ', token)
  
  const directLine = new DirectLineStreaming({
    // conversationId: token.conversationId,
    token: token.token,
    domain: botUrl,
    // webSocket: true,
  });

  console.log('DIRECTLINE ', directLine)
  
  directLine.connectionStatus$.subscribe(connectionStatus => {
    switch (connectionStatus) {
      case ConnectionStatus.Uninitialized: // the status when the DirectLine object is first created/constructed
        console.log('CONNECTION STATUS: UNINITIATED');
        break;
      case ConnectionStatus.Connecting: // currently trying to connect to the conversation
        console.log('CONNECTION STATUS: CONNECTING');
        break;
      case ConnectionStatus.Online: // successfully connected to the converstaion. Connection is healthy so far as we know.
        console.log('CONNECTION STATUS: ONLINE');
        break;
      case ConnectionStatus.ExpiredToken: // last operation errored out with an expired token. Your app should supply a new one.
        console.log('CONNECTION STATUS: EXPIRED TOKEN');
        break;
      case ConnectionStatus.FailedToConnect: // the initial attempt to connect to the conversation failed. No recovery possible.
        console.log('CONNECTION STATUS: FAILED TO CONNECT');
        break;
      case ConnectionStatus.Ended: // the bot ended the conversation
        console.log('CONNECTION STATUS: ENDED');
        break;
    }
  });

  directLine
    .postActivity({
      from: { id: 'myUserId', name: 'myUserName' }, // required (from.name is optional)
      type: 'message',
      text: 'a message for you, Rudy',
    })
    .subscribe(
      id => console.log('Posted activity, assigned ID ', id),
      error => console.log('Error posting activity', error)
    );

  directLine.activity$.subscribe(activity => console.log('received activity ', activity));
}
main();

When running, if directLine.postActivity() is run first then I receive this error:

CONNECTION STATUS: UNINITIATED
CONNECTION STATUS: CONNECTING
C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\botframework-directlinejs\lib\directLineStreaming.js:363
                  return _this3.streamConnection.send(request);
                                                 ^

TypeError: Cannot read properties of undefined (reading 'send')
    at _callee4$ (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\botframework-directlinejs\lib\directLineStreaming.js:363:50)
    at tryCatch (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\regenerator-runtime\runtime.js:64:40)
    at Generator.invoke (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\regenerator-runtime\runtime.js:299:22)
    at Generator.next (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\regenerator-runtime\runtime.js:124:21)
    at asyncGeneratorStep (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\@babel\runtime\helpers\asyncToGenerator.js:3:24)
    at _next (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\@babel\runtime\helpers\asyncToGenerator.js:25:9)
    at C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\@babel\runtime\helpers\asyncToGenerator.js:32:7
    at new Promise (<anonymous>)
    at Observable.<anonymous> (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\@babel\runtime\helpers\asyncToGenerator.js:21:12)
    at Observable._subscribe (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\botframework-directlinejs\lib\directLineStreaming.js:416:24)

However, if directLine.activity$.subscribe() is ran first then I receive this error:

CONNECTION STATUS: UNINITIATED
CONNECTION STATUS: CONNECTING
Failed to connect Error: Unable to connect client to Node transport.
C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\botframework-streaming\lib\webSocket\nodeWebSocketClient.js:63
                throw new Error(`Unable to connect client to Node transport.`);
                      ^

Error: Unable to connect client to Node transport.
    at WebSocketClient.<anonymous> (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\botframework-streaming\lib\webSocket\nodeWebSocketClient.js:63:23)
    at Generator.throw (<anonymous>)
    at rejected (C:\Users\Steven.Kanberg\Source\CustomerSubmits\DirectlineSteaming-386\node_modules\botframework-streaming\lib\webSocket\nodeWebSocketClient.js:13:65)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

With both observables commented out, the DirectLine object is created and the connection status waits in the UNINITIATED state.

Here is what the DirectLineStreaming object looks like, if of use:

{
  'connectionStatus$': BehaviorSubject {
    _isScalar: false,
    observers: [ [Subscriber] ],
    closed: false,
    isStopped: false,
    hasError: false,
    thrownError: null,
    _value: 0
  },
  _botAgent: 'DirectLine/3.0 (directlineStreaming)',
  token: 'eyJhb.....dnurE',
  domain: 'https://some.site.azurewebsites.net/.bot/v3/directline',
  queueActivities: true,
  'activity$': Observable {
    _isScalar: false,
    source: Observable {
      source: [Observable],
      subjectFactory: [Function: shareSubjectFactory]
    },
    operator: RefCountOperator { connectable: [Observable] }
  }
}

While debugging, I noted the two following observations:

  • When connect() is called in the NodeWebSocket class (ref here), the req object's res property is showing null. With my limited knowledge on the inner workings of web sockets, I don't know if this is expected or not.
  • The this.wsSocket property is showing as undefined on line 101. This property is initiated as undefined in the class's constructor and I am unable to access the this.wsSocket = websocket assignment taking place within the completeUpgrade() method. I can't verify if an assignment is actually taking place, so I'm unsure if this is processing correctly.

In either case, the promise on line 105 is returning an error. The issue may be tied to something else, but this is what I noted.

from botframework-directlinejs.

munozemilio avatar munozemilio commented on September 28, 2024

Closing this due to inactivity. Feel free to reopen

from botframework-directlinejs.

orgads avatar orgads commented on September 28, 2024

Please reopen. The issue is not resolved.

from botframework-directlinejs.

orgads avatar orgads commented on September 28, 2024

Superseded by microsoft/botbuilder-js#4412.

from botframework-directlinejs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.