feat: Create flow model and graphQL mutation

This commit is contained in:
Faruk AYDIN
2021-11-22 16:34:13 +01:00
committed by Ömer Faruk Aydın
parent b42cb759a5
commit 8a7d54bb25
12 changed files with 159 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
import CreateTweet from './actions/create-tweet';
export default class Actions {
createTweet: any
constructor(connectionData: any) {
this.createTweet = new CreateTweet(connectionData)
}
}

View File

@@ -0,0 +1,27 @@
import TwitterApi from 'twitter-api-v2';
export default class CreateTweet {
client: any
parameters: any
constructor(connectionData: any, parameters: any) {
this.client = new TwitterApi({
appKey: connectionData.consumerKey,
appSecret: connectionData.consumerSecret,
accessToken: connectionData.accessToken,
accessSecret: connectionData.accessSecret
});
this.parameters = parameters;
}
async run() {
const response = await this.client.currentUser();
const username = response.screen_name;
const userTimeline = await this.client.v1.userTimelineByUsername(username);
const fetchedTweets = userTimeline.tweets;
return fetchedTweets[0];
}
}

View File

@@ -1,12 +1,15 @@
import Authentication from './authentication';
import Triggers from './triggers';
import Actions from './actions';
export default class Twitter {
authenticationClient: any
triggers: any
actions: any
constructor(connectionData: any) {
this.authenticationClient = new Authentication(connectionData);
this.triggers = new Triggers(connectionData);
this.actions = new Actions(connectionData);
}
}

View File

@@ -226,5 +226,19 @@
"key": "userTweet",
"description": "Will be triggered when a specific user tweet something new."
}
],
"actions": [
{
"name": "Create Tweet",
"key": "createTweet",
"description": "Will create a tweet.",
"parameters" : [
{
"name": "Message",
"key": "message",
"required": true
}
]
}
]
}