feat: Implement create tweet action
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { IActionOutput } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Create Tweet',
|
||||
key: 'createTweet',
|
||||
description: 'Create a tweet.',
|
||||
substeps: [
|
||||
{
|
||||
key: 'chooseConnection',
|
||||
name: 'Choose connection',
|
||||
},
|
||||
{
|
||||
key: 'chooseAction',
|
||||
name: 'Set up action',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Tweet body',
|
||||
key: 'tweet',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The content of your new tweet.',
|
||||
variables: true,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: 'testStep',
|
||||
name: 'Test action',
|
||||
},
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const text = $.step.parameters.tweet;
|
||||
const response = await $.http.post('/2/tweets', {
|
||||
text,
|
||||
});
|
||||
|
||||
const tweet: IActionOutput = {
|
||||
data: {
|
||||
raw: response.data,
|
||||
},
|
||||
error: response?.integrationError,
|
||||
};
|
||||
|
||||
return tweet;
|
||||
},
|
||||
});
|
@@ -1,7 +1,13 @@
|
||||
import { Token } from 'oauth-1.0a';
|
||||
import { TBeforeRequest } from '@automatisch/types';
|
||||
import { IJSONObject, TBeforeRequest } from '@automatisch/types';
|
||||
import oauthClient from './oauth-client';
|
||||
|
||||
type RequestDataType = {
|
||||
url: string;
|
||||
method: string;
|
||||
data?: IJSONObject;
|
||||
};
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
const { url, method, data } = requestConfig;
|
||||
|
||||
@@ -10,12 +16,15 @@ const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
secret: $.auth.data?.accessSecret as string,
|
||||
};
|
||||
|
||||
const requestData = {
|
||||
const requestData: RequestDataType = {
|
||||
url: `${requestConfig.baseURL}${url}`,
|
||||
method,
|
||||
data,
|
||||
};
|
||||
|
||||
if (url === '/oauth/request_token') {
|
||||
requestData.data = data;
|
||||
}
|
||||
|
||||
const authHeader = oauthClient($).toHeader(
|
||||
oauthClient($).authorize(requestData, token)
|
||||
);
|
||||
|
Reference in New Issue
Block a user