Skip to content

Commit

Permalink
[Core] Add CustomWebAdapter (+OAuth) (#149)
Browse files Browse the repository at this point in the history
* First try for an util package

* Change to botbuilder-core & add query string parse

* Revert twilioWhatsAppAdapter.ts

* Formatting

* Audit fix

* Add README

* Update changelog

* Update documentation

* Revert twilioWhatsAppAdapter.ts

* Add OAuth support to CustomWebAdapter

* eslint fixes

* Add documentation

* Update documentation

* Bugfix for non existing settings

* Add @nestoralonsovina to credits

Used public details for now, verify if ok

* Update dependencies & fix eslint

* Update OAuth code

* ESLint fixes

* Clean up

* Update readme

* Remove emulated OAuth cards since only supported on emulator

* Update error messages

* ESLint fix

* Change USER_AGENT back to import. Update packages to 4.8.0

* Adaptive card dialog needed to be added to export

* Audit fix

* Change all dependencies to public registry

* Audit fix

* npm audit fix2

* Squashed commit of the following:

commit fa80f07
Author: Mick Vleeshouwer <[email protected]>
Date:   Fri Mar 20 16:55:40 2020 +0100

    Merge pull request #163

    [Core] Update all packages to botbuilder 4.8.0 and correct multiple package-lock.json #163

commit 097923e
Author: Mick Vleeshouwer <[email protected]>
Date:   Fri Mar 20 16:46:03 2020 +0100

    Sync master -> develop (#164)

    * Adaptive card dialog needed to be added to export

    * Audit fix

    Co-authored-by: Michael Szul <[email protected]>

commit 1f1b479
Merge: 7a44067 d2ba4e6
Author: Kyle Delaney <[email protected]>
Date:   Fri Feb 14 08:54:46 2020 -0800

    Merge pull request #157 from iMicknl/adapter/alexa

    [Alexa] Add Alexa Adapter

commit d2ba4e6
Author: Mick Vleeshouwer <[email protected]>
Date:   Fri Feb 14 16:03:49 2020 +0100

    Update dependencies

commit 8af037e
Author: Mick Vleeshouwer <[email protected]>
Date:   Fri Feb 14 16:02:03 2020 +0100

    Bugfix: don’t break on unsupported activities

commit 2c88331
Author: Mick Vleeshouwer <[email protected]>
Date:   Wed Feb 12 00:44:43 2020 +0100

    Update sample to the beta package

commit 216d18b
Author: Mick Vleeshouwer <[email protected]>
Date:   Wed Feb 12 00:40:59 2020 +0100

    Update publish config

commit 17791d0
Author: Mick Vleeshouwer <[email protected]>
Date:   Wed Feb 12 00:31:40 2020 +0100

    Minor changes in documentation and version number

commit d1eee53
Author: Mick Vleeshouwer <[email protected]>
Date:   Wed Feb 12 00:14:48 2020 +0100

    First preview version of Alexa Adapter

commit 7a44067
Merge: fa478f7 f1a469d
Author: Michael Szul <[email protected]>
Date:   Tue Feb 11 07:44:09 2020 -0500

    Merge pull request #156 from BotBuilderCommunity/master

    Updated .npmignore to remove .nyc_output

commit fa478f7
Merge: b8922d8 dd860af
Author: Michael Szul <[email protected]>
Date:   Tue Feb 11 07:35:48 2020 -0500

    Merge pull request #154 from BotBuilderCommunity/master

    [Twilio-WhatsApp] Add support for location messages (inbound & o… (#142)

Co-authored-by: Michael Szul <[email protected]>
  • Loading branch information
iMicknl and szul authored Mar 20, 2020
1 parent fa80f07 commit d2b6731
Show file tree
Hide file tree
Showing 10 changed files with 3,207 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,4 @@ function delay(timeout: number): Promise<void> {
return new Promise((resolve): void => {
setTimeout(resolve, timeout);
});
}
}
3 changes: 3 additions & 0 deletions libraries/botbuilder-core/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
test/
example/
10 changes: 10 additions & 0 deletions libraries/botbuilder-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2020-01
### Added
- Initial release for BotBuilder Community Core
- Add CustomWebAdapter
44 changes: 44 additions & 0 deletions libraries/botbuilder-core/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# BotBuilder Community Core

This package should not be used directly in your Bot Framework chatbot. Instead, it is used in other packages to minimize code repetition.

## CustomWebAdapter

The CustomWebAdapter adds two extra functions to the default `BotAdapter`. `retrieveBody` could be used to retrieve the body of a HTTP request and it will automatically serialize JSON and url-encoded content. `delay` could be used as a helper function for the delay activity.

It is possible to use the [Bot Service OAuth functionality](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-concept-authentication?view=azure-bot-service-4.0) by passing in the optional `BotFrameworkAdapterSettings` object. If you want to implement your own OAuth functionality in `YourOwnAdapter`, you could override the existing OAuth functions found in `IUserTokenProvider`. Sample code for adding OAuth to your bot can be found [here](https://docs.microsoft.com/en-us/azure/bot-service/bot-builder-authentication?view=azure-bot-service-4.0&tabs=javascript).

```typescript
import { CustomWebAdapter } from '@botbuildercommunity/core';

export class YourOwnAdapter extends CustomWebAdapter {

protected readonly yourOwnAdapterSettings: YourOwnAdapterSettings;

public constructor(yourOwnAdapterSettings: YourOwnAdapterSettings, botFrameworkAdapterSettings?: BotFrameworkAdapterSettings) {
// Add optional botFrameworkAdapterSettings to enable OAuth on custom adapters
super(botFrameworkAdapterSettings);
}

public async processActivity(req: WebRequest, res: WebResponse, logic: (context: TurnContext) => Promise<any>): Promise<void> {
const body = this.retrieveBody(req);
...
}

public async sendActivities(context: TurnContext, activities: Partial<Activity>[]): Promise<ResourceResponse[]> {
const responses: ResourceResponse[] = [];

for (let i = 0; i < activities.length; i++) {
const activity: Partial<Activity> = activities[i];

switch (activity.type) {
case 'delay':
await delay(activity.value);
responses.push({} as ResourceResponse);
break;
...
}
}
}
}
```
Loading

0 comments on commit d2b6731

Please sign in to comment.