-
Notifications
You must be signed in to change notification settings - Fork 0
75 lines (65 loc) · 2.28 KB
/
Copy pathnotify_activity.yml
File metadata and controls
75 lines (65 loc) · 2.28 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
name: Notify Activity to Telegram
on:
watch:
types: [started]
fork:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
notify:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: pip install requests
- name: Send notification to Telegram
env:
BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
TOPIC_ID: ${{ secrets.TELEGRAM_TOPIC_ID }}
EVENT_NAME: ${{ github.event_name }}
ACTOR: ${{ github.actor }}
REPO: ${{ github.repository }}
run: |
python -c "
import os, requests
bot_token = os.environ.get('BOT_TOKEN')
chat_id = os.environ.get('CHAT_ID')
topic_id = os.environ.get('TOPIC_ID')
event = os.environ.get('EVENT_NAME')
actor = os.environ.get('ACTOR')
repo = os.environ.get('REPO')
if not bot_token or not chat_id:
print('Telegram credentials not configured.')
exit(0)
if event == 'watch':
action = 'starred'
elif event == 'fork':
action = 'forked'
elif event == 'issues':
action = 'opened an issue in'
elif event == 'pull_request':
action = 'opened a PR in'
else:
action = f'triggered {event} in'
message = f'User [{actor}](https://github.com/{actor}) {action} the repository [{repo}](https://github.com/{repo})!'
url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
payload = {
'chat_id': chat_id,
'text': message,
'parse_mode': 'Markdown',
'disable_web_page_preview': True
}
if topic_id:
payload['message_thread_id'] = topic_id
response = requests.post(url, json=payload)
if response.status_code != 200:
print(f'Failed to send message: {response.status_code} {response.text}')
else:
print('Message sent successfully!')
"