mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
⚡ Add direct message resource to Twitter (#1118)
This commit is contained in:
@@ -38,7 +38,7 @@ import {
|
|||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
import * as clientOAuth1 from 'oauth-1.0a';
|
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 * as clientOAuth2 from 'client-oauth2';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import * as express from 'express';
|
import * as express from 'express';
|
||||||
@@ -238,31 +238,13 @@ export function requestOAuth1(this: IAllExecuteFunctions, credentialsType: strin
|
|||||||
secret: oauthTokenData.oauth_token_secret as string,
|
secret: oauthTokenData.oauth_token_secret as string,
|
||||||
};
|
};
|
||||||
|
|
||||||
const newRequestOptions = {
|
//@ts-ignore
|
||||||
method: requestOptions.method,
|
requestOptions.data = { ...requestOptions.qs, ...requestOptions.form };
|
||||||
data: { ...requestOptions.qs, ...requestOptions.body },
|
|
||||||
json: requestOptions.json,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Some RequestOptions have a URI and some have a URL
|
//@ts-ignore
|
||||||
//@ts-ignores
|
requestOptions.headers = oauth.toHeader(oauth.authorize(requestOptions, token));
|
||||||
if (requestOptions.url !== undefined) {
|
|
||||||
//@ts-ignore
|
|
||||||
newRequestOptions.url = requestOptions.url;
|
|
||||||
} else {
|
|
||||||
//@ts-ignore
|
|
||||||
newRequestOptions.url = requestOptions.uri;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (requestOptions.qs !== undefined) {
|
return this.helpers.request!(requestOptions)
|
||||||
//@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)
|
|
||||||
.catch(async (error: IResponseError) => {
|
.catch(async (error: IResponseError) => {
|
||||||
// Unknown error so simply throw it
|
// Unknown error so simply throw it
|
||||||
throw error;
|
throw error;
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
import {
|
||||||
|
INodeProperties,
|
||||||
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
export const directMessageOperations = [
|
||||||
|
{
|
||||||
|
displayName: 'Operation',
|
||||||
|
name: 'operation',
|
||||||
|
type: 'options',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
resource: [
|
||||||
|
'directMessage',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Create',
|
||||||
|
value: 'create',
|
||||||
|
description: 'Create a direct message',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
default: 'create',
|
||||||
|
description: 'The operation to perform.',
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
|
|
||||||
|
export const directMessageFields = [
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* directMessage:create */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
{
|
||||||
|
displayName: 'User ID',
|
||||||
|
name: 'userId',
|
||||||
|
type: 'string',
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'directMessage',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'The ID of the user who should receive the direct message.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Text',
|
||||||
|
name: 'text',
|
||||||
|
type: 'string',
|
||||||
|
typeOptions: {
|
||||||
|
alwaysOpenEditWindow: true,
|
||||||
|
},
|
||||||
|
required: true,
|
||||||
|
default: '',
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'directMessage',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
description: 'The text of your Direct Message. URL encode as necessary. Max length of 10,000 characters.',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
displayName: 'Additional Fields',
|
||||||
|
name: 'additionalFields',
|
||||||
|
type: 'collection',
|
||||||
|
placeholder: 'Add Field',
|
||||||
|
default: {},
|
||||||
|
displayOptions: {
|
||||||
|
show: {
|
||||||
|
operation: [
|
||||||
|
'create',
|
||||||
|
],
|
||||||
|
resource: [
|
||||||
|
'directMessage',
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
displayName: 'Attachment',
|
||||||
|
name: 'attachment',
|
||||||
|
type: 'string',
|
||||||
|
default: 'data',
|
||||||
|
description: 'Name of the binary propertie which contain<br />data which should be added to directMessage as attachment.',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
] as INodeProperties[];
|
||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
} from 'request';
|
} from 'request';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
BINARY_ENCODING,
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
IExecuteSingleFunctions,
|
IExecuteSingleFunctions,
|
||||||
IHookFunctions,
|
IHookFunctions,
|
||||||
@@ -10,7 +11,8 @@ import {
|
|||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IDataObject,
|
IBinaryKeyData,
|
||||||
|
IDataObject, INodeExecutionData,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
export async function twitterApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IHookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
export async function twitterApiRequest(this: IExecuteFunctions | IExecuteSingleFunctions | ILoadOptionsFunctions | IHookFunctions, method: string, resource: string, body: any = {}, qs: IDataObject = {}, uri?: string, option: IDataObject = {}): Promise<any> { // tslint:disable-line:no-any
|
||||||
@@ -28,6 +30,9 @@ export async function twitterApiRequest(this: IExecuteFunctions | IExecuteSingle
|
|||||||
if (Object.keys(body).length === 0) {
|
if (Object.keys(body).length === 0) {
|
||||||
delete options.body;
|
delete options.body;
|
||||||
}
|
}
|
||||||
|
if (Object.keys(qs).length === 0) {
|
||||||
|
delete options.qs;
|
||||||
|
}
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
return await this.helpers.requestOAuth1.call(this, 'twitterOAuth1Api', options);
|
return await this.helpers.requestOAuth1.call(this, 'twitterOAuth1Api', options);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -74,3 +79,105 @@ export function chunks (buffer: Buffer, chunkSize: number) {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function uploadAttachments(this: IExecuteFunctions, binaryProperties: string[], items: INodeExecutionData[], i: number) {
|
||||||
|
|
||||||
|
const uploadUri = 'https://upload.twitter.com/1.1/media/upload.json';
|
||||||
|
|
||||||
|
const media: IDataObject[] = [];
|
||||||
|
|
||||||
|
for (const binaryPropertyName of binaryProperties) {
|
||||||
|
|
||||||
|
const binaryData = items[i].binary as IBinaryKeyData;
|
||||||
|
|
||||||
|
if (binaryData === undefined) {
|
||||||
|
throw new Error('No binary data set. So file can not be written!');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!binaryData[binaryPropertyName]) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let attachmentBody = {};
|
||||||
|
let response: IDataObject = {};
|
||||||
|
|
||||||
|
const isAnimatedWebp = (Buffer.from(binaryData[binaryPropertyName].data, 'base64').toString().indexOf('ANMF') !== -1);
|
||||||
|
|
||||||
|
const isImage = binaryData[binaryPropertyName].mimeType.includes('image');
|
||||||
|
|
||||||
|
if (isImage && isAnimatedWebp) {
|
||||||
|
throw new Error('Animated .webp images are not supported use .gif instead');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isImage) {
|
||||||
|
|
||||||
|
const attachmentBody = {
|
||||||
|
media_data: binaryData[binaryPropertyName].data,
|
||||||
|
};
|
||||||
|
|
||||||
|
response = await twitterApiRequest.call(this, 'POST', '', {}, {}, uploadUri, { form: attachmentBody });
|
||||||
|
|
||||||
|
media.push(response);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-init
|
||||||
|
|
||||||
|
attachmentBody = {
|
||||||
|
command: 'INIT',
|
||||||
|
total_bytes: Buffer.from(binaryData[binaryPropertyName].data, BINARY_ENCODING).byteLength,
|
||||||
|
media_type: binaryData[binaryPropertyName].mimeType,
|
||||||
|
};
|
||||||
|
|
||||||
|
response = await twitterApiRequest.call(this, 'POST', '', {}, {}, uploadUri, { form: attachmentBody });
|
||||||
|
|
||||||
|
const mediaId = response.media_id_string;
|
||||||
|
|
||||||
|
// break the data on 5mb chunks (max size that can be uploaded at once)
|
||||||
|
|
||||||
|
const binaryParts = chunks(Buffer.from(binaryData[binaryPropertyName].data, BINARY_ENCODING), 5242880);
|
||||||
|
|
||||||
|
let index = 0;
|
||||||
|
|
||||||
|
for (const binaryPart of binaryParts) {
|
||||||
|
|
||||||
|
//https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-append
|
||||||
|
|
||||||
|
attachmentBody = {
|
||||||
|
name: binaryData[binaryPropertyName].fileName,
|
||||||
|
command: 'APPEND',
|
||||||
|
media_id: mediaId,
|
||||||
|
media_data: Buffer.from(binaryPart).toString('base64'),
|
||||||
|
segment_index: index,
|
||||||
|
};
|
||||||
|
|
||||||
|
response = await twitterApiRequest.call(this, 'POST', '', {}, {}, uploadUri, { form: attachmentBody });
|
||||||
|
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
//https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-finalize
|
||||||
|
|
||||||
|
attachmentBody = {
|
||||||
|
command: 'FINALIZE',
|
||||||
|
media_id: mediaId,
|
||||||
|
};
|
||||||
|
|
||||||
|
response = await twitterApiRequest.call(this, 'POST', '', {}, {}, uploadUri, { form: attachmentBody });
|
||||||
|
|
||||||
|
// data has not been uploaded yet, so wait for it to be ready
|
||||||
|
if (response.processing_info) {
|
||||||
|
const { check_after_secs } = (response.processing_info as IDataObject);
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
setTimeout(() => {
|
||||||
|
resolve();
|
||||||
|
}, (check_after_secs as number) * 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
media.push(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
return media;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,10 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
BINARY_ENCODING,
|
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
ILoadOptionsFunctions,
|
ILoadOptionsFunctions,
|
||||||
} from 'n8n-core';
|
} from 'n8n-core';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IBinaryKeyData,
|
|
||||||
IDataObject,
|
IDataObject,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
INodePropertyOptions,
|
INodePropertyOptions,
|
||||||
@@ -14,21 +12,25 @@ import {
|
|||||||
INodeTypeDescription,
|
INodeTypeDescription,
|
||||||
} from 'n8n-workflow';
|
} from 'n8n-workflow';
|
||||||
|
|
||||||
|
import {
|
||||||
|
directMessageFields,
|
||||||
|
directMessageOperations,
|
||||||
|
} from './DirectMessageDescription';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
tweetFields,
|
tweetFields,
|
||||||
tweetOperations,
|
tweetOperations,
|
||||||
} from './TweetDescription';
|
} from './TweetDescription';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
chunks,
|
|
||||||
twitterApiRequest,
|
twitterApiRequest,
|
||||||
twitterApiRequestAllItems,
|
twitterApiRequestAllItems,
|
||||||
|
uploadAttachments,
|
||||||
} from './GenericFunctions';
|
} from './GenericFunctions';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ITweet,
|
ITweet,
|
||||||
} from './TweetInterface';
|
} from './TweetInterface';
|
||||||
import { isDate } from 'util';
|
|
||||||
|
|
||||||
const ISO6391 = require('iso-639-1');
|
const ISO6391 = require('iso-639-1');
|
||||||
|
|
||||||
@@ -59,6 +61,10 @@ export class Twitter implements INodeType {
|
|||||||
name: 'resource',
|
name: 'resource',
|
||||||
type: 'options',
|
type: 'options',
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
name: 'Direct Message',
|
||||||
|
value: 'directMessage',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Tweet',
|
name: 'Tweet',
|
||||||
value: 'tweet',
|
value: 'tweet',
|
||||||
@@ -67,6 +73,9 @@ export class Twitter implements INodeType {
|
|||||||
default: 'tweet',
|
default: 'tweet',
|
||||||
description: 'The resource to operate on.',
|
description: 'The resource to operate on.',
|
||||||
},
|
},
|
||||||
|
// DIRECT MESSAGE
|
||||||
|
...directMessageOperations,
|
||||||
|
...directMessageFields,
|
||||||
// TWEET
|
// TWEET
|
||||||
...tweetOperations,
|
...tweetOperations,
|
||||||
...tweetFields,
|
...tweetFields,
|
||||||
@@ -101,6 +110,45 @@ export class Twitter implements INodeType {
|
|||||||
const resource = this.getNodeParameter('resource', 0) as string;
|
const resource = this.getNodeParameter('resource', 0) as string;
|
||||||
const operation = this.getNodeParameter('operation', 0) as string;
|
const operation = this.getNodeParameter('operation', 0) as string;
|
||||||
for (let i = 0; i < length; i++) {
|
for (let i = 0; i < length; i++) {
|
||||||
|
if (resource === 'directMessage') {
|
||||||
|
//https://developer.twitter.com/en/docs/twitter-api/v1/direct-messages/sending-and-receiving/api-reference/new-event
|
||||||
|
if (operation === 'create') {
|
||||||
|
const userId = this.getNodeParameter('userId', i) as string;
|
||||||
|
const text = this.getNodeParameter('text', i) as string;
|
||||||
|
const additionalFields = this.getNodeParameter('additionalFields', i) as IDataObject;
|
||||||
|
const body: IDataObject = {
|
||||||
|
type: 'message_create',
|
||||||
|
message_create: {
|
||||||
|
target: {
|
||||||
|
recipient_id: userId,
|
||||||
|
},
|
||||||
|
message_data: {
|
||||||
|
text,
|
||||||
|
attachment: {},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
if (additionalFields.attachment) {
|
||||||
|
const attachment = additionalFields.attachment as string;
|
||||||
|
|
||||||
|
const attachmentProperties: string[] = attachment.split(',').map((propertyName) => {
|
||||||
|
return propertyName.trim();
|
||||||
|
});
|
||||||
|
|
||||||
|
const medias = await uploadAttachments.call(this, attachmentProperties, items, i);
|
||||||
|
//@ts-ignore
|
||||||
|
body.message_create.message_data.attachment = { type: 'media', media: { id: medias[0].media_id_string } };
|
||||||
|
} else {
|
||||||
|
//@ts-ignore
|
||||||
|
delete body.message_create.message_data.attachment;
|
||||||
|
}
|
||||||
|
|
||||||
|
responseData = await twitterApiRequest.call(this, 'POST', '/direct_messages/events/new.json', { event: body });
|
||||||
|
|
||||||
|
responseData = responseData.event;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (resource === 'tweet') {
|
if (resource === 'tweet') {
|
||||||
// https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update
|
// https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-update
|
||||||
if (operation === 'create') {
|
if (operation === 'create') {
|
||||||
@@ -109,129 +157,43 @@ export class Twitter implements INodeType {
|
|||||||
const body: ITweet = {
|
const body: ITweet = {
|
||||||
status: text,
|
status: text,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (additionalFields.inReplyToStatusId) {
|
if (additionalFields.inReplyToStatusId) {
|
||||||
body.in_reply_to_status_id = additionalFields.inReplyToStatusId as string;
|
body.in_reply_to_status_id = additionalFields.inReplyToStatusId as string;
|
||||||
body.auto_populate_reply_metadata = true;
|
body.auto_populate_reply_metadata = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalFields.attachments) {
|
if (additionalFields.attachments) {
|
||||||
const mediaIds = [];
|
|
||||||
const attachments = additionalFields.attachments as string;
|
const attachments = additionalFields.attachments as string;
|
||||||
const uploadUri = 'https://upload.twitter.com/1.1/media/upload.json';
|
|
||||||
|
|
||||||
const attachmentProperties: string[] = attachments.split(',').map((propertyName) => {
|
const attachmentProperties: string[] = attachments.split(',').map((propertyName) => {
|
||||||
return propertyName.trim();
|
return propertyName.trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const binaryPropertyName of attachmentProperties) {
|
const medias = await uploadAttachments.call(this, attachmentProperties, items, i);
|
||||||
|
|
||||||
const binaryData = items[i].binary as IBinaryKeyData;
|
body.media_ids = (medias as IDataObject[]).map((media: IDataObject) => media.media_id_string).join(',');
|
||||||
|
|
||||||
if (binaryData === undefined) {
|
|
||||||
throw new Error('No binary data set. So file can not be written!');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!binaryData[binaryPropertyName]) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
let attachmentBody = {};
|
|
||||||
let response: IDataObject = {};
|
|
||||||
|
|
||||||
const isAnimatedWebp = (Buffer.from(binaryData[binaryPropertyName].data, 'base64').toString().indexOf('ANMF') !== -1);
|
|
||||||
|
|
||||||
const isImage = binaryData[binaryPropertyName].mimeType.includes('image');
|
|
||||||
|
|
||||||
if (isImage && isAnimatedWebp) {
|
|
||||||
throw new Error('Animated .webp images are not supported use .gif instead');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isImage) {
|
|
||||||
|
|
||||||
const attachmentBody = {
|
|
||||||
media_data: binaryData[binaryPropertyName].data,
|
|
||||||
};
|
|
||||||
|
|
||||||
response = await twitterApiRequest.call(this, 'POST', '', attachmentBody, {}, uploadUri);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-init
|
|
||||||
|
|
||||||
attachmentBody = {
|
|
||||||
command: 'INIT',
|
|
||||||
total_bytes: Buffer.from(binaryData[binaryPropertyName].data, BINARY_ENCODING).byteLength,
|
|
||||||
media_type: binaryData[binaryPropertyName].mimeType,
|
|
||||||
};
|
|
||||||
|
|
||||||
response = await twitterApiRequest.call(this, 'POST', '', attachmentBody, {}, uploadUri);
|
|
||||||
|
|
||||||
const mediaId = response.media_id_string;
|
|
||||||
|
|
||||||
// break the data on 5mb chunks (max size that can be uploaded at once)
|
|
||||||
|
|
||||||
const binaryParts = chunks(Buffer.from(binaryData[binaryPropertyName].data, BINARY_ENCODING), 5242880);
|
|
||||||
|
|
||||||
let index = 0;
|
|
||||||
|
|
||||||
for (const binaryPart of binaryParts) {
|
|
||||||
|
|
||||||
//https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-append
|
|
||||||
|
|
||||||
attachmentBody = {
|
|
||||||
name: binaryData[binaryPropertyName].fileName,
|
|
||||||
command: 'APPEND',
|
|
||||||
media_id: mediaId,
|
|
||||||
media_data: Buffer.from(binaryPart).toString('base64'),
|
|
||||||
segment_index: index,
|
|
||||||
};
|
|
||||||
|
|
||||||
response = await twitterApiRequest.call(this, 'POST', '', attachmentBody, {}, uploadUri);
|
|
||||||
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//https://developer.twitter.com/en/docs/media/upload-media/api-reference/post-media-upload-finalize
|
|
||||||
|
|
||||||
attachmentBody = {
|
|
||||||
command: 'FINALIZE',
|
|
||||||
media_id: mediaId,
|
|
||||||
};
|
|
||||||
|
|
||||||
response = await twitterApiRequest.call(this, 'POST', '', attachmentBody, {}, uploadUri);
|
|
||||||
|
|
||||||
// data has not been uploaded yet, so wait for it to be ready
|
|
||||||
if (response.processing_info) {
|
|
||||||
const { check_after_secs } = (response.processing_info as IDataObject);
|
|
||||||
await new Promise((resolve, reject) => {
|
|
||||||
setTimeout(() => {
|
|
||||||
resolve();
|
|
||||||
}, (check_after_secs as number) * 1000);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mediaIds.push(response.media_id_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
body.media_ids = mediaIds.join(',');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalFields.possiblySensitive) {
|
if (additionalFields.possiblySensitive) {
|
||||||
body.possibly_sensitive = additionalFields.possibly_sensitive as boolean;
|
body.possibly_sensitive = additionalFields.possiblySensitive as boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (additionalFields.displayCoordinates) {
|
||||||
|
body.display_coordinates = additionalFields.displayCoordinates as boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (additionalFields.locationFieldsUi) {
|
if (additionalFields.locationFieldsUi) {
|
||||||
const locationUi = additionalFields.locationFieldsUi as IDataObject;
|
const locationUi = additionalFields.locationFieldsUi as IDataObject;
|
||||||
if (locationUi.locationFieldsValues) {
|
if (locationUi.locationFieldsValues) {
|
||||||
const values = locationUi.locationFieldsValues as IDataObject;
|
const values = locationUi.locationFieldsValues as IDataObject;
|
||||||
body.lat = parseFloat(values.lalatitude as string);
|
body.lat = parseFloat(values.latitude as string);
|
||||||
body.long = parseFloat(values.lalatitude as string);
|
body.long = parseFloat(values.longitude as string);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
responseData = await twitterApiRequest.call(this, 'POST', '/statuses/update.json', body);
|
responseData = await twitterApiRequest.call(this, 'POST', '/statuses/update.json', {}, body as unknown as IDataObject);
|
||||||
}
|
}
|
||||||
// https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets
|
// https://developer.twitter.com/en/docs/tweets/search/api-reference/get-search-tweets
|
||||||
if (operation === 'search') {
|
if (operation === 'search') {
|
||||||
|
|||||||
Reference in New Issue
Block a user