feat: Implement search tweet trigger step for twitter

This commit is contained in:
Faruk AYDIN
2022-03-12 14:27:15 +03:00
committed by Ömer Faruk Aydın
parent 3f7a888429
commit ab82134b88
4 changed files with 60 additions and 3 deletions

View File

@@ -19,7 +19,7 @@ export default class Twitter implements IService {
parameters: IJSONObject
) {
this.authenticationClient = new Authentication(appData, connectionData);
this.triggers = new Triggers(connectionData);
this.triggers = new Triggers(connectionData, parameters);
this.actions = new Actions(connectionData, parameters);
}
}

View File

@@ -258,6 +258,33 @@
"name": "Test trigger"
}
]
},
{
"name": "Search Tweet",
"key": "searchTweet",
"description": "Will be triggered when any user tweet something containing a specific keyword, phrase, username or hashtag.",
"subSteps": [
{
"key": "chooseAccount",
"name": "Choose account"
},
{
"key": "chooseTrigger",
"name": "Set up a trigger",
"arguments": [
{
"label": "Search Term",
"key": "searchTerm",
"type": "string",
"required": true
}
]
},
{
"key": "testStep",
"name": "Test trigger"
}
]
}
],
"actions": [

View File

@@ -1,10 +1,13 @@
import MyTweet from './triggers/my-tweet';
import { IJSONObject } from '@automatisch/types';
import MyTweet from './triggers/my-tweet';
import SearchTweet from './triggers/search-tweet';
export default class Triggers {
myTweet: MyTweet;
searchTweet: SearchTweet;
constructor(connectionData: IJSONObject) {
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
this.myTweet = new MyTweet(connectionData);
this.searchTweet = new SearchTweet(connectionData, parameters);
}
}

View File

@@ -0,0 +1,27 @@
import TwitterApi, { TwitterApiTokens } from 'twitter-api-v2';
import { IJSONObject } from '@automatisch/types';
export default class SearchTweet {
client: TwitterApi;
parameters: IJSONObject;
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
this.client = new TwitterApi({
appKey: connectionData.consumerKey,
appSecret: connectionData.consumerSecret,
accessToken: connectionData.accessToken,
accessSecret: connectionData.accessSecret,
} as TwitterApiTokens);
this.parameters = parameters;
}
async run() {
const response = await this.client.v2.get('tweets/search/recent', {
query: this.parameters.searchTerm as string,
max_results: 100,
});
return response.data;
}
}