Add direct message resource to Twitter (#1118)

This commit is contained in:
Ricardo Espinoza
2020-11-03 17:01:38 -05:00
committed by GitHub
parent ad75f17e98
commit 7c049fa858
4 changed files with 277 additions and 128 deletions

View File

@@ -38,7 +38,7 @@ import {
} from 'n8n-workflow';
import * as clientOAuth1 from 'oauth-1.0a';
import { RequestOptions, Token } from 'oauth-1.0a';
import { Token } from 'oauth-1.0a';
import * as clientOAuth2 from 'client-oauth2';
import { get } from 'lodash';
import * as express from 'express';
@@ -238,31 +238,13 @@ export function requestOAuth1(this: IAllExecuteFunctions, credentialsType: strin
secret: oauthTokenData.oauth_token_secret as string,
};
const newRequestOptions = {
method: requestOptions.method,
data: { ...requestOptions.qs, ...requestOptions.body },
json: requestOptions.json,
};
//@ts-ignore
requestOptions.data = { ...requestOptions.qs, ...requestOptions.form };
// Some RequestOptions have a URI and some have a URL
//@ts-ignores
if (requestOptions.url !== undefined) {
//@ts-ignore
newRequestOptions.url = requestOptions.url;
} else {
//@ts-ignore
newRequestOptions.url = requestOptions.uri;
}
//@ts-ignore
requestOptions.headers = oauth.toHeader(oauth.authorize(requestOptions, token));
if (requestOptions.qs !== undefined) {
//@ts-ignore
newRequestOptions.qs = oauth.authorize(newRequestOptions as RequestOptions, token);
} else {
//@ts-ignore
newRequestOptions.form = oauth.authorize(newRequestOptions as RequestOptions, token);
}
return this.helpers.request!(newRequestOptions)
return this.helpers.request!(requestOptions)
.catch(async (error: IResponseError) => {
// Unknown error so simply throw it
throw error;