-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DirectlineStreaming doesn't work with Node.js #386
Comments
@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 |
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"
}
} |
@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. |
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
However, if
With both observables commented out, the DirectLine object is created and the connection status waits in the 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:
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. |
Closing this due to inactivity. Feel free to reopen |
Please reopen. The issue is not resolved. |
Superseded by microsoft/botbuilder-js#4412. |
When trying to replace Directline with DirectlineStreaming, the websocket connection fails.
The failure is in botframework-streaming/lib/webSocket/nodeWebSocketClient.
this._url
is the full URL (in my case that's wss://my-streaming-bot.azurewebsites.net/.bot/v3/directline/conversations/connect?token=eyJh...), and not the host alone, so websocket initialization throws an exception.Moreover, the error message is not reflected to the calling code. It just writes "Unable to connect client to Node transport.".
Minimal example follows.
The text was updated successfully, but these errors were encountered: