Merge pull request #470 from automatisch/feature/my-tweets
feat: Implement my tweets trigger
This commit is contained in:
@@ -218,8 +218,8 @@
|
||||
],
|
||||
"triggers": [
|
||||
{
|
||||
"name": "My Tweet",
|
||||
"key": "myTweet",
|
||||
"name": "My Tweets",
|
||||
"key": "myTweets",
|
||||
"description": "Will be triggered when you tweet something new.",
|
||||
"substeps": [
|
||||
{
|
||||
|
@@ -1,15 +1,18 @@
|
||||
import TwitterClient from './client';
|
||||
import UserTweets from './triggers/user-tweets';
|
||||
import SearchTweets from './triggers/search-tweets';
|
||||
import MyTweets from './triggers/my-tweets';
|
||||
|
||||
export default class Triggers {
|
||||
client: TwitterClient;
|
||||
userTweets: UserTweets;
|
||||
searchTweets: SearchTweets;
|
||||
myTweets: MyTweets;
|
||||
|
||||
constructor(client: TwitterClient) {
|
||||
this.client = client;
|
||||
this.userTweets = new UserTweets(client);
|
||||
this.searchTweets = new SearchTweets(client);
|
||||
this.myTweets = new MyTweets(client);
|
||||
}
|
||||
}
|
||||
|
@@ -1,25 +0,0 @@
|
||||
import TwitterApi, { TwitterApiTokens } from 'twitter-api-v2';
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
|
||||
export default class MyTweet {
|
||||
client: TwitterApi;
|
||||
|
||||
constructor(connectionData: IJSONObject) {
|
||||
this.client = new TwitterApi({
|
||||
appKey: connectionData.consumerKey,
|
||||
appSecret: connectionData.consumerSecret,
|
||||
accessToken: connectionData.accessToken,
|
||||
accessSecret: connectionData.accessSecret,
|
||||
} as TwitterApiTokens);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
25
packages/backend/src/apps/twitter/triggers/my-tweets.ts
Normal file
25
packages/backend/src/apps/twitter/triggers/my-tweets.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import TwitterClient from '../client';
|
||||
|
||||
export default class MyTweets {
|
||||
client: TwitterClient;
|
||||
|
||||
constructor(client: TwitterClient) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
async run(lastInternalId: string) {
|
||||
return this.getTweets(lastInternalId);
|
||||
}
|
||||
|
||||
async testRun() {
|
||||
return this.getTweets();
|
||||
}
|
||||
|
||||
async getTweets(lastInternalId?: string) {
|
||||
const { username } = await this.client.getCurrentUser.run();
|
||||
const user = await this.client.getUserByUsername.run(username as string);
|
||||
|
||||
const tweets = await this.client.getUserTweets.run(user.id, lastInternalId);
|
||||
return tweets;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user