feat: Create flow model and graphQL mutation
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
b42cb759a5
commit
8a7d54bb25
9
packages/backend/src/apps/twitter/actions.ts
Normal file
9
packages/backend/src/apps/twitter/actions.ts
Normal 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)
|
||||
}
|
||||
}
|
27
packages/backend/src/apps/twitter/actions/create-tweet.ts
Normal file
27
packages/backend/src/apps/twitter/actions/create-tweet.ts
Normal 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];
|
||||
}
|
||||
}
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
Reference in New Issue
Block a user