Skip to content

Commit 0d54459

Browse files
authored
🔧 config: Refactor Twitter & Telegram Actions (#108)
1 parent aa158c0 commit 0d54459

8 files changed

Lines changed: 259 additions & 174 deletions

.github/workflows/joining-tweet.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/reminder-tweet.yaml

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: Reminder Tweet
2+
3+
on:
4+
schedule:
5+
# Schedule job 10 minutes before time to account for delays
6+
# Every Saturday at 11:20 AM UTC (05:00 PM IST - 10 min)
7+
- cron: "20 11 * * SAT"
8+
# Every Saturday at 04:30 PM UTC (10:10 PM IST - 10 min)
9+
- cron: "30 16 * * SAT"
10+
workflow_dispatch:
11+
inputs:
12+
message-template:
13+
type: choice
14+
required: true
15+
default: automatic
16+
options:
17+
- automatic
18+
- reminder
19+
- joining
20+
description: |
21+
Which message template to use.
22+
if set to `automatic`, resolves to:
23+
`joining`, if time is after 10pm on Saturday (IST)
24+
`reminder`, otherwise
25+
26+
jobs:
27+
send-messages:
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout repository
31+
uses: actions/checkout@v2
32+
with:
33+
persist-credentials: false
34+
35+
- name: Set environment variables
36+
run: |
37+
upcoming_catchup_number=$(node util/get-next-catchup-number.js)
38+
echo "UPCOMING_CATCHUP_NUMBER=${upcoming_catchup_number}" >> ${GITHUB_ENV}
39+
40+
prev_catchup_number=$(node util/get-latest-catchup-number.js)
41+
echo "PREV_CATCHUP_NUMBER=${prev_catchup_number}" >> ${GITHUB_ENV}
42+
43+
catchup_date=$(date +"%b %d")
44+
echo "CATCHUP_DATE=${catchup_date}" >> ${GITHUB_ENV}
45+
46+
message_template=${{ inputs.message-template }}
47+
if [ "${message_template}" = "automatic" ]; then
48+
message_template=$(node util/get-current-message-template.js)
49+
fi
50+
echo "MESSAGE_TEMPLATE=${message_template}" >> ${GITHUB_ENV}
51+
52+
# Reminder messages
53+
- name: Wait until 17:00 IST
54+
if: ${{ env.MESSAGE_TEMPLATE }} == 'reminder'
55+
run: sleep $(node util\get-seconds-until-ist-time.js 17:00)
56+
57+
- name: Send reminder Telegram message
58+
if: ${{ env.MESSAGE_TEMPLATE }} == 'reminder'
59+
run: |
60+
export TELEGRAM_MESSAGE="Reminder! 🚨
61+
62+
The ${{ env.UPCOMING_CATCHUP_NUMBER }} OTC CatchUp session will be held today (${{ env.CATCHUP_DATE }}) from 10:30 PM IST.
63+
64+
Join us for an informal open-to-all Tech discussion!
65+
66+
Joining link 👇
67+
https://catchup.ourtech.community/attend
68+
69+
Previous session details 👇
70+
https://catchup.ourtech.community/summary/${{ env.PREV_CATCHUP_NUMBER }}"
71+
72+
BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }} node util/post-telegram-message.js
73+
74+
- name: Send reminder Tweet
75+
if: ${{ env.MESSAGE_TEMPLATE }} == 'reminder'
76+
uses: Eomm/why-don-t-you-tweet@v1
77+
with:
78+
tweet-message: |
79+
Reminder! 🚨
80+
81+
The ${{ env.UPCOMING_CATCHUP_NUMBER }} OTC CatchUp session will be held today (${{ env.CATCHUP_DATE }}) from 10:30 PM IST.
82+
83+
Join us for an informal open-to-all Tech discussion!
84+
85+
Previous session details 👇
86+
https://catchup.ourtech.community/summary/${{ env.PREV_CATCHUP_NUMBER }}
87+
88+
#OTC #OTCCatchUp #Community #Tech
89+
env:
90+
TWITTER_CONSUMER_API_KEY: ${{ secrets.TWITTER_API_KEY }}
91+
TWITTER_CONSUMER_API_SECRET: ${{ secrets.TWITTER_API_KEY_SECRET }}
92+
TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
93+
TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}
94+
95+
# Joining messages
96+
- name: Wait until 22:10 IST
97+
if: ${{ env.MESSAGE_TEMPLATE }} == 'joining'
98+
run: sleep $(node util/get-seconds-until-ist-time.js 22:10)
99+
100+
- name: Send joining Telegram message
101+
if: ${{ env.MESSAGE_TEMPLATE }} == 'joining'
102+
run: |
103+
export TELEGRAM_MESSAGE="<b>${{ env.UPCOMING_CATCHUP_NUMBER }} OTC CatchUp</b>
104+
105+
An informal open-to-all Tech discussion!
106+
107+
We start at 10:30 PM IST.
108+
109+
Join in at any time! 👇
110+
https://catchup.ourtech.community/attend"
111+
112+
BOT_TOKEN=${{ secrets.TELEGRAM_BOT_TOKEN }} node util/post-telegram-message.js
113+
114+
- name: Send joining Tweet
115+
if: ${{ env.MESSAGE_TEMPLATE }} == 'joining'
116+
uses: Eomm/why-don-t-you-tweet@v1
117+
with:
118+
tweet-message: |
119+
Going live in 30 mins!
120+
121+
Join us for the ${{ env.UPCOMING_CATCHUP_NUMBER }} #OTCCatchUp, an informal open-to-all Tech discussion.
122+
123+
Join in at any time! 👇
124+
https://catchup.ourtech.community/attend
125+
env:
126+
TWITTER_CONSUMER_API_KEY: ${{ secrets.TWITTER_API_KEY }}
127+
TWITTER_CONSUMER_API_SECRET: ${{ secrets.TWITTER_API_KEY_SECRET }}
128+
TWITTER_ACCESS_TOKEN: ${{ secrets.TWITTER_ACCESS_TOKEN }}
129+
TWITTER_ACCESS_TOKEN_SECRET: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }}

.github/workflows/tg-joining-msg.yaml

Lines changed: 0 additions & 38 deletions
This file was deleted.

.github/workflows/tg-reminder-msg.yaml

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function getCurrentMessageTemplate(date = new Date()) {
2+
let istDate = new Date(
3+
date.toLocaleString("en-US", {
4+
timeZone: "Asia/Kolkata"
5+
})
6+
);
7+
8+
// if time is after 10pm on saturday return joining,
9+
// else return reminder
10+
// 6 is Saturday
11+
if (istDate.getDay() === 6 && istDate.getHours() >= 22) return "joining";
12+
else return "reminder";
13+
}
14+
15+
module.exports = {
16+
getCurrentMessageTemplate
17+
};
18+
19+
if (require.main) console.log(getCurrentMessageTemplate());

util/get-seconds-until-ist-time.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const time = process.argv[2];
2+
const [hours, minutes] = time.split(":");
3+
if (!time || !hours || !minutes) {
4+
console.error(`invalid timestamp: ${time}`);
5+
process.exit(1);
6+
}
7+
8+
let now = new Date(
9+
new Date().toLocaleString("en-US", {
10+
timeZone: "Asia/Kolkata"
11+
})
12+
);
13+
14+
let date = new Date(now);
15+
16+
let seconds = Math.floor((date.getTime() - now.getTime()) / 1000);
17+
if (seconds < 0) seconds = 0;
18+
console.log(seconds);

0 commit comments

Comments
 (0)