feat: Implement search tweet trigger step for twitter
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
3f7a888429
commit
ab82134b88
@@ -19,7 +19,7 @@ export default class Twitter implements IService {
|
|||||||
parameters: IJSONObject
|
parameters: IJSONObject
|
||||||
) {
|
) {
|
||||||
this.authenticationClient = new Authentication(appData, connectionData);
|
this.authenticationClient = new Authentication(appData, connectionData);
|
||||||
this.triggers = new Triggers(connectionData);
|
this.triggers = new Triggers(connectionData, parameters);
|
||||||
this.actions = new Actions(connectionData, parameters);
|
this.actions = new Actions(connectionData, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -258,6 +258,33 @@
|
|||||||
"name": "Test trigger"
|
"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": [
|
"actions": [
|
||||||
|
@@ -1,10 +1,13 @@
|
|||||||
import MyTweet from './triggers/my-tweet';
|
|
||||||
import { IJSONObject } from '@automatisch/types';
|
import { IJSONObject } from '@automatisch/types';
|
||||||
|
import MyTweet from './triggers/my-tweet';
|
||||||
|
import SearchTweet from './triggers/search-tweet';
|
||||||
|
|
||||||
export default class Triggers {
|
export default class Triggers {
|
||||||
myTweet: MyTweet;
|
myTweet: MyTweet;
|
||||||
|
searchTweet: SearchTweet;
|
||||||
|
|
||||||
constructor(connectionData: IJSONObject) {
|
constructor(connectionData: IJSONObject, parameters: IJSONObject) {
|
||||||
this.myTweet = new MyTweet(connectionData);
|
this.myTweet = new MyTweet(connectionData);
|
||||||
|
this.searchTweet = new SearchTweet(connectionData, parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
packages/backend/src/apps/twitter/triggers/search-tweet.ts
Normal file
27
packages/backend/src/apps/twitter/triggers/search-tweet.ts
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user