-
Notifications
You must be signed in to change notification settings - Fork 128
Add streaming protocol support #183
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
Merged
Merged
Changes from all commits
Commits
Show all changes
90 commits
Select commit
Hold shift + click to select a range
3c0b4d7
Added dependency to protocol
ckkMicrosoft a5770d7
Start conversation is sent.
ckkMicrosoft 72eeec9
Connection works
ckkMicrosoft 6c4fe9b
DLJS Works a little bit ...
ckkMicrosoft 5c4152f
Working version
ckkMicrosoft 509d420
Make old and new work together
ckkMicrosoft 1e58ca1
Cleanup
ckkMicrosoft 476ada3
minor refactoring
ckkMicrosoft ed7cf06
Fixed the dependency on protocol
ckkMicrosoft 32ef35d
Do not use conversation id during connect
ckkMicrosoft 1c98f60
Support posting of attachments over streaming protocol
ckkMicrosoft afd4344
Minor correction.
ckkMicrosoft 8277df0
Make the attachments inline.
ckkMicrosoft 226228e
Incorporate name change
ckkMicrosoft 7b13339
Remove old protocol dependencies
ckkMicrosoft 3b8446a
Update to match changes in streaming extensions module, fix build iss…
DDEfromOR 5faaaa8
With tests
ckkMicrosoft 96f804c
Add CI build
compulim d1488a2
Use BotBuilder-JS with PR #1132
compulim 554cdf7
Use later build
compulim ab438b0
Update TGZ
compulim 69949f8
Add Git tag
compulim 5aac776
Update build script
compulim 5321b47
Update script
compulim de1d6ec
Enable tests
compulim a657e6e
Add CONTRIBUTING.md
compulim 12ae233
Verbage
compulim 470aa1a
Fix for streaming post activity test.
ckkashyap 2729809
post activit works
ckkashyap 8d6180d
Added conversationUpdate test
ckkashyap 2d997b0
fixed streaming extensions library casing
ckkashyap acd58de
Added the right tgz
ckkashyap 72d155c
addressed review comment
ckkashyap fc3a9ae
Fixed a couple of attachment bugs
ckkMicrosoft 868bc89
Commenting out streaming tests to see if it makes Travis happy
ckkMicrosoft bc8b74e
Fixed minor bug.
ckkMicrosoft cffc2a5
New streaming extensions library
ckkMicrosoft c1726ef
All tests pass
ckkMicrosoft 2da26fb
Valdiate the attachment content
ckkMicrosoft 8421b1a
Changed the contenttype field to type to match the change in the stre…
ckkMicrosoft 398f689
Add a newer webpack
ckkashyap aa269e2
receive attachment test
ckkashyap 487b823
Extracted out the streaming logic into another file
ckkashyap 288c921
retry works
ckkashyap 46edb56
removed the need for ActivityGroup
ckkashyap 4040497
new connect
ckkashyap f1d5f2e
cleaned up
ckkashyap ef4f01a
cleanup
ckkashyap 4efefe2
post error is handled
ckkashyap f88a9af
formatting
ckkashyap e2bb360
conversation id and referencegrammar set
ckkashyap 028cdbf
retry added
ckkashyap 869916c
remove unused code
ckkashyap 5100b95
added token refresh
ckkashyap 4b0a48f
refresh updated
ckkashyap 7fab4bc
refresh retry
ckkashyap d87c555
referencegrammar set
ckkashyap b438194
js equal stuff
ckkashyap 6ec2204
import reordering
ckkashyap e064c6f
remove extra blank line
ckkashyap 3e10f06
directline fixed
ckkashyap 70ea9c2
All tests pass with the C# bot
ckkashyap 67b0a19
right streaming tgz
ckkashyap 7c96a94
fixed test
ckkashyap 710736c
commented out the attachment test
ckkashyap 839ac56
fixed the attachment order bug
ckkashyap 9c4d029
add my username
ckkashyap 07d2215
some refactoring
ckkashyap c67116b
minor refactoring
ckkashyap 077b3f4
Change the dependency to npm
ckkMicrosoft 27c27ea
Updated the package-lock.json
ckkMicrosoft de844be
Merge remote-tracking branch 'origin/master' into ckk/protocoljs
ckkMicrosoft d08e911
Fix failing test
ckkMicrosoft 27b20b0
Addressed some review comments.
ckkMicrosoft 1e14f1b
remove commented out line
ckkMicrosoft c756228
Addressed some review comments
ckkMicrosoft f8c23e9
Addressed more comments.
ckkMicrosoft 88c6864
More review comments addressed
ckkMicrosoft 3846dc3
Addressed more comments.
ckkMicrosoft 8493cb1
Addressed more comments.
ckkMicrosoft a0e5db7
Addressed more comments.
ckkMicrosoft c3638d1
Addressed more comments
ckkMicrosoft e3c452f
Changed the custructor option
ckkMicrosoft 5df1be7
Addressed more comments.
ckkMicrosoft 933a446
Added support for IE11
ckkMicrosoft 3f8f306
Switched to using fetch
ckkMicrosoft 50aed67
Refresh token uses fetch now
ckkMicrosoft ce22168
Moved the connect logic away from rxjs
ckkMicrosoft 61b9a6d
Addressed review comments
ckkMicrosoft 087ac72
Point to preview version of botframework-streaming on npm
ckkMicrosoft File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # Direct Line Streaming Extensions | ||
|
|
||
| This is CONTRIBUTING.md for Direct Line Streaming Extensions. | ||
|
|
||
| ## Run automated tests | ||
|
|
||
| - Clone this repository branch | ||
| - `npm ci` | ||
| - Please ignore `node-gyp` errors, it is a warning instead | ||
| - `npm test` | ||
|
|
||
| > You don't need to run `npm run build`. Jest will rebuild the source code on-the-fly for each test run. | ||
|
|
||
| If you want to run tests in watch mode, run `npm test -- --watch`. | ||
|
|
||
| ## Build development bundle | ||
|
|
||
| - Clone this repository | ||
| - `npm ci` | ||
| - `npm run build` | ||
|
|
||
| After build succeeded, you can use the JavaScript bundle at `/dist/directline.js`. This is development build. It is not minified and contains instrumentation code for code coverage. | ||
|
|
||
| To use the bundle: | ||
|
|
||
| ```js | ||
| const { DirectLine } = window.DirectLine; | ||
|
|
||
| const directLine = new DirectLineStreaming({ | ||
| conversationId: '<required>', | ||
| domain: 'https://.../.bot/v3/directline', | ||
| token: '<required>', | ||
| webSocket: true | ||
| }); | ||
|
|
||
| // Start the connection and console-logging every incoming activity | ||
| directLine.activity$.subscribe({ | ||
| next(activity) { console.log(activity); } | ||
| }); | ||
| ``` | ||
|
|
||
| ## CI/CD pipeline | ||
|
|
||
| ### Build status | ||
|
|
||
| For latest build status, navigate to https://travis-ci.org/microsoft/BotFramework-DirectLineJS/branches, and select `ckk/protocoljs` branch. | ||
|
|
||
| ### Test in Web Chat | ||
|
|
||
| The last successful build can be tested with Web Chat and MockBot. | ||
|
|
||
| - Navigate to https://compulim.github.io/webchat-loader/ | ||
| - Click `Dev` or select `<Latest development bit>` from the dropdown list | ||
| - Click `[Public] MockBot with Streaming Extensions` | ||
| - Click `Open Web Chat in a new window` | ||
|
|
||
| Type `help` to MockBot for list of commands. | ||
|
|
||
| ### Build artifacts | ||
|
|
||
| After successful build, artifacts are published to https://github.com/microsoft/BotFramework-DirectLineJS/releases/tag/dev-streamingextensions. | ||
|
|
||
| For easier consumption, in the assets, [`directline.js`](https://github.com/microsoft/BotFramework-DirectLineJS/releases/download/dev-streamingextensions/directline.js) is the bundle from last successful build. You can use the HTML code below to use latest DirectLineJS with Web Chat 4.5.2: | ||
|
|
||
| ```html | ||
| <!DOCTYPE html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <title>Web Chat with Streaming Extensions</title> | ||
| <script src="https://cdn.botframework.com/botframework-webchat/latest/webchat-es5.js"></script> | ||
| <script src="https://github.com/microsoft/BotFramework-DirectLineJS/releases/download/dev-streamingextensions/directline.js"></script> | ||
| <style type="text/css"> | ||
| html, body, body > div { height: 100%; } | ||
| body { margin: 0; } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <script> | ||
| const { DirectLine } = window.DirectLine; | ||
| const webChatElement = document.createElement('div'); | ||
|
|
||
| window.WebChat.renderWebChat({ | ||
| directLine: new DirectLine({ | ||
| conversationId: '<required>', | ||
| domain: 'https://.../.bot/v3/directline', | ||
| token: '<required>', | ||
| webSocket: true | ||
| }) | ||
| }, webChatElement); | ||
|
|
||
| document.body.append(webChatElement); | ||
| </script> | ||
| </body> | ||
| </html> | ||
| ``` | ||
|
|
||
| ### Source code | ||
|
|
||
| Run `git checkout dev-streamingextensions` to checkout the source code of the last successful build. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import 'dotenv/config'; | ||
|
|
||
| import onErrorResumeNext from 'on-error-resume-next'; | ||
|
|
||
| import { timeouts } from './constants.json'; | ||
| import * as createDirectLine from './setup/createDirectLine'; | ||
| import waitForBotToRespond from './setup/waitForBotToRespond'; | ||
| import waitForConnected from './setup/waitForConnected'; | ||
|
|
||
| describe('Happy path', () => { | ||
| let unsubscribes; | ||
|
|
||
| beforeEach(() => unsubscribes = []); | ||
| afterEach(() => unsubscribes.forEach(fn => onErrorResumeNext(fn))); | ||
|
|
||
| describe('should receive the welcome message from bot', () => { | ||
| let directLine; | ||
|
|
||
| describe('using REST', () => { | ||
| beforeEach(() => jest.setTimeout(timeouts.rest)); | ||
|
|
||
| test('with token', async () => { | ||
| directLine = await createDirectLine.forREST({ token: true }); | ||
| }); | ||
| }); | ||
|
|
||
| test('using Streaming Extensions', async () => { | ||
| jest.setTimeout(timeouts.webSocket); | ||
| directLine = await createDirectLine.forStreamingExtensions(); | ||
| }); | ||
|
|
||
| describe('using Web Socket', () => { | ||
| beforeEach(() => jest.setTimeout(timeouts.webSocket)); | ||
|
|
||
| test('with token', async () => { | ||
| directLine = await createDirectLine.forWebSocket({ token: true }); | ||
| }); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| // If directLine object is undefined, that means the test is failing. | ||
| if (!directLine) { return; } | ||
|
|
||
| unsubscribes.push(directLine.end.bind(directLine)); | ||
|
|
||
| await waitForBotToRespond(directLine, ({ text }) => text === 'Welcome') | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import 'dotenv/config'; | ||
|
|
||
| import onErrorResumeNext from 'on-error-resume-next'; | ||
|
|
||
| import { timeouts } from './constants.json'; | ||
| import * as createDirectLine from './setup/createDirectLine'; | ||
| import fetchAsBase64 from './setup/fetchAsBase64'; | ||
| import postActivity from './setup/postActivity'; | ||
| import waitForBotToEcho from './setup/waitForBotToEcho'; | ||
| import waitForConnected from './setup/waitForConnected'; | ||
| import waitForBotToRespond from './setup/waitForBotToRespond.js'; | ||
|
|
||
| describe('Happy path', () => { | ||
| let unsubscribes; | ||
|
|
||
| beforeEach(() => unsubscribes = []); | ||
| afterEach(() => unsubscribes.forEach(fn => onErrorResumeNext(fn))); | ||
|
|
||
| describe('receive attachments', () => { | ||
| let directLine; | ||
|
|
||
| test('using Streaming Extensions', async () => { | ||
| jest.setTimeout(timeouts.webSocket); | ||
| directLine = await createDirectLine.forStreamingExtensions(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| // If directLine object is undefined, that means the test is failing. | ||
| if (!directLine) { return; } | ||
|
|
||
| unsubscribes.push(directLine.end.bind(directLine)); | ||
| unsubscribes.push(await waitForConnected(directLine)); | ||
|
|
||
| let url1 = 'http://myasebot.azurewebsites.net/177KB.jpg'; | ||
| let url2 = 'http://myasebot.azurewebsites.net/100KB.jpg'; | ||
|
|
||
| const activityFromUser = { | ||
| text: 'attach ' + url1 + ' ' + url2, | ||
| type: 'message', | ||
| channelData: { | ||
| testType: "streaming" | ||
| } | ||
| }; | ||
|
|
||
| await Promise.all([ | ||
| postActivity(directLine, activityFromUser), | ||
| waitForBotToRespond(directLine, async (activity) => { | ||
| if (!activity.channelData){ | ||
| return false; | ||
| } | ||
| let attachmentContents1 = await fetchAsBase64(url1); | ||
| let attachmentContents2 = await fetchAsBase64(url2); | ||
| const prefixLength = "data:text/plain;base64,".length; | ||
| return (activity.attachments.length == 2 && | ||
| attachmentContents1 == activity.attachments[0].contentUrl.substr(prefixLength) && | ||
| attachmentContents2 == activity.attachments[1].contentUrl.substr(prefixLength)); | ||
| }) | ||
| ]); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| import 'dotenv/config'; | ||
|
|
||
| import onErrorResumeNext from 'on-error-resume-next'; | ||
|
|
||
| import { timeouts } from './constants.json'; | ||
| import * as createDirectLine from './setup/createDirectLine'; | ||
| import fetchAsBase64 from './setup/fetchAsBase64'; | ||
| import postActivity from './setup/postActivity'; | ||
| import waitForBotToEcho from './setup/waitForBotToEcho'; | ||
| import waitForConnected from './setup/waitForConnected'; | ||
|
|
||
| describe('Happy path', () => { | ||
| let unsubscribes; | ||
|
|
||
| beforeEach(() => unsubscribes = []); | ||
| afterEach(() => unsubscribes.forEach(fn => onErrorResumeNext(fn))); | ||
|
|
||
| describe('upload 2 attachments with text messages', () => { | ||
| let directLine; | ||
|
|
||
| test('using Streaming Extensions', async () => { | ||
| jest.setTimeout(timeouts.webSocket); | ||
| directLine = await createDirectLine.forStreamingExtensions(); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| // If directLine object is undefined, that means the test is failing. | ||
| if (!directLine) { return; } | ||
|
|
||
| unsubscribes.push(directLine.end.bind(directLine)); | ||
| unsubscribes.push(await waitForConnected(directLine)); | ||
|
|
||
| const activityFromUser = { | ||
| // DirectLine.postActivityWithAttachments support "contentUrl" only but not "content" | ||
| attachments: [{ | ||
| contentType: 'image/jpg', | ||
| contentUrl: 'http://myasebot.azurewebsites.net/177KB.jpg' | ||
| }, { | ||
| contentType: 'image/jpg', | ||
| contentUrl: 'http://myasebot.azurewebsites.net/100KB.jpg' | ||
| }], | ||
| text: 'Hello, World!', | ||
| type: 'message', | ||
| channelData: { | ||
| testType: "streaming" | ||
| } | ||
| }; | ||
|
|
||
| await Promise.all([ | ||
| postActivity(directLine, activityFromUser), | ||
| waitForBotToEcho(directLine, async ({ attachments, text }) => { | ||
| if (text === 'Hello, World!' && attachments) { | ||
| const [expectedContents, actualContents] = await Promise.all([ | ||
| Promise.all([ | ||
| fetchAsBase64(activityFromUser.attachments[0].contentUrl), | ||
| fetchAsBase64(activityFromUser.attachments[1].contentUrl) | ||
| ]), | ||
| ]); | ||
|
|
||
|
|
||
| let result = ( (expectedContents[0] === attachments[0].contentUrl && | ||
| expectedContents[1] === attachments[1].contentUrl) || | ||
| (expectedContents[1] === attachments[0].contentUrl && | ||
| expectedContents[0] === attachments[1].contentUrl) ); | ||
|
|
||
| if (!result) { | ||
| console.warn(attachments[0].contentUrl); | ||
| console.warn(attachments[1].contentUrl); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| }) | ||
| ]); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.