generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tweet.ts
35 lines (32 loc) · 1 KB
/
tweet.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Twitter from 'twitter'
export async function tweet(
status: string,
mediaIds: string[] = [],
inReplyToStatusId = ''
): Promise<string> {
return new Promise((resolve, reject) => {
const consumer_key = process.env.CONSUMER_API_KEY as string
const consumer_secret = process.env.CONSUMER_API_SECRET_KEY as string
const access_token_key = process.env.ACCESS_TOKEN as string
const access_token_secret = process.env.ACCESS_TOKEN_SECRET as string
const client = new Twitter({
consumer_key,
consumer_secret,
access_token_key,
access_token_secret
})
const parameters: {[key: string]: string} = {status}
if (mediaIds.length > 0) {
parameters['media_ids'] = mediaIds.join(',')
}
if (inReplyToStatusId !== '') {
parameters['in_reply_to_status_id'] = inReplyToStatusId
}
client.post('statuses/update', parameters, (errors, data, response) => {
if (errors) {
reject(errors)
}
resolve(response.body)
})
})
}