Skip to content

Commit

Permalink
update axios in release/1.5 (#924)
Browse files Browse the repository at this point in the history
* update axios in release/1.5

* rewrite how custom access token be handled
  • Loading branch information
chentsulin authored Sep 13, 2021
1 parent b0ba5d0 commit a90f674
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 485 deletions.
16 changes: 14 additions & 2 deletions packages/bottender-facebook/src/FacebookConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,23 @@ export default class FacebookConnector
}
}

let client;
if (customAccessToken) {
client = new FacebookClient({
accessToken: customAccessToken,
appSecret: this._appSecret,
origin: this._origin,
skipAppSecretProof: this._skipAppSecretProof,
});
} else {
client = this._client;
}

if (params.event instanceof FacebookEvent) {
return new FacebookContext({
...params,
event: params.event,
client: this._client,
client,
customAccessToken,
batchQueue: this._batchQueue,
appId: this._appId,
Expand All @@ -179,7 +191,7 @@ export default class FacebookConnector
return new MessengerContext({
...params,
event: params.event,
client: this._client,
client,
customAccessToken,
batchQueue: this._batchQueue,
appId: this._appId,
Expand Down
6 changes: 4 additions & 2 deletions packages/bottender-facebook/src/FacebookContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ export default class FacebookContext extends Context<

if (this._batchQueue) {
return this._batchQueue.push<MessengerTypes.SendMessageSuccessResponse>(
// FIXME: this type should be fixed in MessengerBatch
MessengerBatch.sendText(recipient, text, {
accessToken: this._customAccessToken,
})
} as any)
);
}
return this._client.sendText(recipient, text);
Expand Down Expand Up @@ -148,9 +149,10 @@ export default class FacebookContext extends Context<

if (this._batchQueue) {
return this._batchQueue.push<MessengerTypes.SendMessageSuccessResponse>(
// FIXME: this type should be fixed in MessengerBatch
MessengerBatch.sendMessage(recipient, message, {
accessToken: this._customAccessToken,
})
} as any)
);
}
return this._client.sendMessage(recipient, message);
Expand Down
4 changes: 2 additions & 2 deletions packages/bottender-luis/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "@bottender/luis",
"version": "1.5.1-alpha.9",
"description": "LUIS integration for Bottender.",
"license": "MIT",
"homepage": "https://bottender.js.org/",
"repository": {
"type": "git",
"url": "https://github.com/Yoctol/bottender.git"
},
"version": "1.5.1-alpha.9",
"main": "dist/index.js",
"files": [
"dist"
],
"types": "dist/index.d.ts",
"dependencies": {
"axios": "^0.19.2",
"axios": "^0.21.4",
"invariant": "^2.2.4"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/bottender-qna-maker/package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"name": "@bottender/qna-maker",
"version": "1.5.1-alpha.9",
"description": "QnA Maker integration for Bottender.",
"license": "MIT",
"homepage": "https://bottender.js.org/",
"repository": {
"type": "git",
"url": "https://github.com/Yoctol/bottender.git"
},
"version": "1.5.1-alpha.9",
"main": "dist/index.js",
"files": [
"dist"
],
"types": "dist/index.d.ts",
"dependencies": {
"axios": "^0.19.2",
"axios": "^0.21.4",
"invariant": "^2.2.4"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/bottender-rasa/package.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{
"name": "@bottender/rasa",
"version": "1.5.1-alpha.9",
"description": "Rasa NLU integration for Bottender.",
"license": "MIT",
"homepage": "https://bottender.js.org/",
"repository": {
"type": "git",
"url": "https://github.com/Yoctol/bottender.git"
},
"version": "1.5.1-alpha.9",
"main": "dist/index.js",
"files": [
"dist"
],
"types": "dist/index.d.ts",
"dependencies": {
"@types/lodash": "^4.14.149",
"axios": "^0.19.2",
"axios": "^0.21.4",
"lodash": "^4.17.15"
},
"peerDependencies": {
Expand Down
18 changes: 9 additions & 9 deletions packages/bottender/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "bottender",
"version": "1.5.1-alpha.9",
"description": "A framework for building conversational user interfaces.",
"license": "MIT",
"homepage": "https://bottender.js.org/",
"repository": {
"type": "git",
"url": "https://github.com/Yoctol/bottender.git"
},
"version": "1.5.1-alpha.9",
"main": "dist/index.js",
"browser": "dist/browser.js",
"bin": {
Expand Down Expand Up @@ -43,7 +43,7 @@
"@types/update-notifier": "^4.1.0",
"@types/warning": "^3.0.0",
"arg": "^4.1.3",
"axios": "^0.19.2",
"axios": "^0.21.4",
"axios-error": "^1.0.0-beta.27",
"body-parser": "^1.19.0",
"chalk": "~2.4.2",
Expand All @@ -54,7 +54,7 @@
"delay": "^4.3.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"facebook-batch": "1.0.0-beta.32",
"facebook-batch": "1.0.6",
"figures": "^3.2.0",
"file-type": "^14.1.3",
"fs-extra": "^8.1.0",
Expand All @@ -67,12 +67,12 @@
"jsonfile": "^6.0.0",
"lodash": "^4.17.15",
"lru-cache": "^5.1.1",
"messaging-api-common": "1.0.0-beta.29",
"messaging-api-line": "1.0.0-beta.33",
"messaging-api-messenger": "1.0.0-beta.33",
"messaging-api-slack": "1.0.0-beta.33",
"messaging-api-telegram": "1.0.0-beta.33",
"messaging-api-viber": "1.0.0-beta.33",
"messaging-api-common": "1.0.4",
"messaging-api-line": "1.0.6",
"messaging-api-messenger": "1.0.6",
"messaging-api-slack": "1.0.6",
"messaging-api-telegram": "1.0.6",
"messaging-api-viber": "1.0.6",
"minimist": "^1.2.0",
"mongodb": "^3.5.4",
"ngrok": "^3.4.1",
Expand Down
7 changes: 7 additions & 0 deletions packages/bottender/src/messenger/FacebookBaseConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export default class FacebookBaseConnector<

_appSecret: string;

_origin: string | undefined = undefined;

_skipAppSecretProof: boolean | undefined = undefined;

_mapPageToAccessToken: ((pageId: string) => Promise<string>) | null = null;

_verifyToken: string | null = null;
Expand Down Expand Up @@ -91,6 +95,9 @@ export default class FacebookBaseConnector<
this._batchConfig
);
}

this._origin = origin;
this._skipAppSecretProof = skipAppSecretProof;
}

this._appId = appId;
Expand Down
29 changes: 25 additions & 4 deletions packages/bottender/src/messenger/MessengerConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,17 @@ export default class MessengerConnector
} else {
let user = {};
try {
user = await this._client.getUserProfile(senderId as any, {
accessToken: customAccessToken,
});
if (customAccessToken) {
const client = new MessengerClient({
accessToken: customAccessToken,
appSecret: this._appSecret,
origin: this._origin,
skipAppSecretProof: this._skipAppSecretProof,
});
user = await client.getUserProfile(senderId as any);
} else {
user = await this._client.getUserProfile(senderId as any);
}
} catch (err) {
warning(
false,
Expand Down Expand Up @@ -243,9 +251,22 @@ export default class MessengerConnector
customAccessToken = await this._mapPageToAccessToken(pageId);
}
}

let client;
if (customAccessToken) {
client = new MessengerClient({
accessToken: customAccessToken,
appSecret: this._appSecret,
origin: this._origin,
skipAppSecretProof: this._skipAppSecretProof,
});
} else {
client = this._client;
}

return new MessengerContext({
...params,
client: this._client,
client,
customAccessToken,
batchQueue: this._batchQueue,
appId: this._appId,
Expand Down
Loading

0 comments on commit a90f674

Please sign in to comment.