Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrown committed Oct 28, 2019
2 parents 59c7ac1 + c22d360 commit 9c477fc
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions packages/botbuilder-adapter-facebook/src/facebook_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,26 @@ export class FacebookAPI {
* @param method HTTP method, for example POST, GET, DELETE or PUT.
* @param payload An object to be sent as parameters to the API call.
*/
public async callAPI(path: string, method: string = 'POST', payload: any): Promise<any> {
let proof = this.getAppSecretProof(this.token, this.secret);
public async callAPI(path: string, method: string = 'POST', payload: any = {}): Promise<any> {
const proof = this.getAppSecretProof(this.token, this.secret);

let queryString = '?';
let body = {};

if (method.toUpperCase() === 'GET') {
for(const key in payload) {
queryString = queryString + `${encodeURIComponent(key)}=${encodeURIComponent(payload[key])}&`;
}
} else {
body = payload;
}

return new Promise((resolve, reject) => {
request({
method: method,
method: method.toUpperCase(),
json: true,
body: payload,
uri: 'https://' + this.api_host + '/' + this.api_version + path + '?access_token=' + this.token + '&appsecret_proof=' + proof
body,
uri: `https://${this.api_host}/${this.api_version}${path}${queryString}access_token=${this.token}&appsecret_proof=${proof}`
}, (err, res, body) => {
if (err) {
reject(err);
Expand Down

0 comments on commit 9c477fc

Please sign in to comment.