Skip to content

Commit 9e613b6

Browse files
authored
Merge pull request #1 from aps08/dev
Merging Dev to Main
2 parents 70d3043 + ba7d352 commit 9e613b6

File tree

19 files changed

+1118
-142
lines changed

19 files changed

+1118
-142
lines changed

.github/workflows/actions.yml

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,44 @@
1-
name: teltotwt
1+
name: tweegramBot in Action
22

33
on:
4-
push:
5-
branches:
6-
- main
4+
schedule:
5+
- cron: "0 * * * *"
76

87
jobs:
98
build:
109
runs-on: ubuntu-latest
11-
timeout-minutes: 4
10+
timeout-minutes: 3
1211
steps:
13-
- name: checkout repository
12+
- name: Checkout tweegramBot repository
1413
uses: actions/checkout@v3
1514

16-
- name: setup python
15+
- name: Setting python 3.10
1716
uses: actions/setup-python@v4
1817
with:
1918
python-version: "3.10"
2019

21-
- name: install python packages
20+
- name: Installing python packages
2221
run: |
2322
python -m pip install --upgrade pip
2423
pip install -r requirements.txt
25-
- name: execution
24+
25+
- name: Setting environmental variables and executing
2626
env:
27-
TEL_API_ID: ${{ secrets.TEL_API_ID }}
28-
TEL_API_HASH: ${{ secrets.TEL_API_HASH }}
29-
TEL_GROUP: ${{ secrets.TEL_GROUP }}
30-
TWT_API_KEY: ${{ secrets.TWT_API_KEY }}
31-
TWT_API_SECRET: ${{ secrets.TWT_API_SECRET }}
32-
TWT_ACCESS_TOKEN: ${{ secrets.TWT_ACCESS_TOKEN }}
33-
TWT_ACCESS_TOKEN_SECRET: ${{ secrets.TWT_ACCESS_TOKEN_SECRET }}
27+
ENTITY: ${{ secrets.ENTITY }}
28+
USERNAME: ${{ secrets.USERNAME }}
29+
API_ID: ${{ secrets.API_ID }}
30+
API_HASH: ${{ secrets.API_HASH }}
31+
BEARER_TOKEN: ${{ secrets.BEARER_TOKEN }}
32+
API_KEY: ${{ secrets.API_KEY }}
33+
API_SECRET: ${{ secrets.API_SECRET }}
34+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
35+
ACCESS_TOKEN_SECRET: ${{ secrets.ACCESS_TOKEN_SECRET }}
3436
run: python src/main.py
3537

36-
- name: auto commit
38+
- name: Auto commit from GitHub Actions
3739
run: |
38-
git config --local user.email "${{ secrets.EMAIL }}"
39-
git config --local user.name "aps08"
40-
git add .
41-
git commit -m "Commit from Github Actions"
42-
git push -f origin main
40+
git config --local user.email "<GITHUB USERNAME>@users.noreply.github.com"
41+
git config --local user.name "<GITHUB USERNAME>"
42+
git add -A
43+
git commit -m "Automated Commit"
44+
git push

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ __pycache__/
55

66
# C extensions
77
*.so
8-
8+
.env
99
# Distribution / packaging
1010
.Python
1111
build/

.vscode/settings.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
"editor.formatOnSave": true,
33
"python.formatting.provider": "black",
44
"python.formatting.blackArgs": [
5-
"--line-length=100"
5+
"--line-length=120"
66
],
7-
"python.sortImports.args": [
7+
"isort.args": [
88
"--profile=black"
99
],
1010
"python.linting.lintOnSave": true,
@@ -13,5 +13,14 @@
1313
"editor.codeActionsOnSave": {
1414
"source.organizeImports": true
1515
}
16-
}
16+
},
17+
"python.testing.unittestArgs": [
18+
"-v",
19+
"-s",
20+
"./tests/",
21+
"-p",
22+
"*_test.py"
23+
],
24+
"python.testing.pytestEnabled": false,
25+
"python.testing.unittestEnabled": true
1726
}

README.md

Lines changed: 63 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,76 @@
1-
# twigramBot
1+
![banner](./docs/images/banner.png)
2+
<p align="center">
3+
<img src="https://img.shields.io/badge/Visual_Studio_Code-0078D4?style=for-the-badge&logo=visual%20studio%20code&logoColor=white" alt="vscode">
4+
<img src="https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54" alt="Python">
5+
<img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white" alt="Twitter">
6+
<img src="https://img.shields.io/badge/GitHub_Actions-2088FF?style=for-the-badge&logo=github-actions&logoColor=white" alt="GitHub Actions">
7+
<img src="https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white" alt="Telegram">
8+
</p>
9+
10+
# tweegramBot
11+
A semi-configured respository, which help you convert your telegram messages to twitter tweets, also retweet the tweets tweeted by specific list of users.
12+
13+
### How to use
14+
* Fork this repository.
15+
* Get your API_ID and API_HASH for telegram from [here](https://my.telegram.org/apps).
16+
* Create a python file in your local, and paste the code given below.
17+
```python
18+
from telethon.sync import TelegramClient
19+
20+
client = TelegramClient("tweegramBot", "<API_ID>", "<API_HASH>").start()
21+
```
22+
* Give your number and enter code you get on telegram, and that will create a `tweegramBot.session` file. Now place this `tweegramBot.session` file at the root directory of this respository you have forked.
23+
* It is recommended to not keep the repository in public, with the `*.session`, which was created in the first step, and `*.json` file which will be created when you add users to your list.
24+
* Get your BEARER_TOKEN, API_KEY, API_SECRET, ACCESS_TOKEN and ACCESS_TOKEN_SECRET for twitter from [here](https://developer.twitter.com/en/portal/dashboard).
25+
* Set the API secrets you generated in the 2nd and 6th step. A total of 9 secret need to be created, which inclued 7 API secret, USERNAME (*twitter username of the bot*) and ENTITY(*telegram username for the account from which you want to transfer the text to twitter*). Learn how to create repository secrets [here](https://docs.github.com/en/actions/security-guides/encrypted-secrets).
26+
* Secrets will look like these once setup.
27+
28+
<img src="./docs/images/secrets.png" width="400" height="400">
29+
* Once the above steps are completed, this repo will run every hour, and convert all your telegram messages into tweets.
30+
* *IMPORTANT*: Make sure to give `read and write permission` to github action for this repository under settings section.
31+
32+
### Command features you can use on telegram
33+
```
34+
@add <TWITTER USERNAME> => adds the user to white list.
35+
@notice <YOUR MESSAGE> => these message will be considered as notice for telegram channel, and not be tweeted.
36+
@remove <TWITTER USERNAME> => removes the user from white list.
37+
```
38+
#### Example
39+
Command | Twitter Tweet | Telegram message|
40+
------------- | ------------- | ---------------|
41+
@add [aps08__](https://twitter.com/aps08__) | Thank you for joining us [@aps08__](https://twitter.com/aps08__).You have been added to our list with #JBDS34B34B. | ❌
42+
@notice Do not copy paste. | ❌ | ❌
43+
@remove aps08__ | ❌ | [aps08__](https://twitter.com/aps08__) tweeter user has been removed.
244

3-
twigramBot is a mini-script, which helps you to convert telegram messages to twitter tweets.
45+
### Default configuration and description
46+
You can see the Default class, which is present inside the [`src/main.py`](https://github.com/aps08/tweegramBot/blob/main/src/main.py). Now you can see what each variables mean in the below table.
447

5-
## Made with
6-
![code](https://img.shields.io/badge/Visual_Studio_Code-0078D4?style=for-the-badge&logo=visual%20studio%20code&logoColor=white)
7-
![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)
8-
![Twitter](https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white)
9-
![Github Action](https://img.shields.io/badge/GitHub_Actions-2088FF?style=for-the-badge&logo=github-actions&logoColor=white)
10-
![Telegram](https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white)
1148

12-
## How to use
13-
1. Get your API secrets for telegram from [here](https://my.telegram.org/apps).
14-
2. Get your API secrets for twitter from [here](https://developer.twitter.com/en/portal/dashboard).
15-
3. Fork this reposiotry, and uncomment the commented lines in [this](https://github.com/aps08/teltotwt/blob/main/.github/workfows/actions.yml) file.
16-
4. Create secrets for this repository. Total 8 secret key-value pair need to be created, 6 of them would be the API secrets, 1 would be telegram group/user name and 1 would be your github email. You can see the keys and instructions in [this](https://github.com/aps08/teltotwt/blob/main/src/config.py) file.
17-
5. Once the above steps are completed, this repo will run everyday at mid-night, and convert all your telegram messages into tweets.
49+
Variable | Description |
50+
------------- | ------------- |
51+
USERNAME | username of the twitter account, taken from the environmental variable.
52+
FIRST_COMMENT | Default `False`, when True and if you pass a link with an image, the image will be tweeted first and the link will be tweeted in the first comment.
53+
COMMAND_CHECK | Default `True`, when False telegram commands will not work.
54+
FILE_NAME | Name of the json file, which stores the list of users. Default `member_info`.
55+
PREFIX | adds the prefix to the token for easy identification for verification. Default `GTR`.
56+
RETWEET_TEXT | Retweet quote. We cannot create a rewteet with a quote. Default `Retweeting for better reach. \U0001F603`
57+
ADD_MESSAGE | Tweet notification message when a user is added to the json file. Default `Thank you for joining us @{}.You have been added to our list with #{}.` Make sure to give 2 `{}` for token and twitter username for tagging, when making changes.
58+
REMOVE_MESSAGE | Telegram notification when user is removed from the list. Default `{} tweeter user has been removed.` Make sure to pass `{}` in the string to add the username.
59+
ONLY_IMG_MESSAGE | This Message is required when you are tweeting only an image. Default `Opening \U0001F603`.
60+
RETWEET_MENTIONED | Default `True`, when False, the retweet functinality will not work.
61+
SEND_LOG_ON_ERR | Default `True`, when False you won't receive the logs on telegram when there is an error or warning.
1862

19-
## Note
20-
1. *For this to work, one time manual process is required for telegram, where a session file will be generated.*
21-
2. *Do not keep the repository in public, with the **session** file*.
63+
### Bad news
64+
This project was in progress from past few weeks, so I am releasing it. The decision by twitter and API cost might affect the future of this project. Read [here](https://twitter.com/TwitterDev/status/1621026986784337922?t=AYvhqkC0gqApLV-Qw19hlA&s=19)
2265

66+
<p align="center" style="text"><strong>If you liked something about this repository, do give it a 🌟. It will motivate me come up with more such project. You can reach out to me on my social media given below.</strong></p>
2367

24-
## Where to find me
25-
26-
<p align="left">
68+
<p align="center">
2769
<a href="https://twitter.com/aps08__"><img src="https://img.shields.io/badge/Twitter-1DA1F2?style=for-the-badge&logo=twitter&logoColor=white"></a>
2870
<a href="https://medium.com/@aps08"><img src="https://img.shields.io/badge/Medium-12100E?style=for-the-badge&logo=medium&logoColor=white"></a>
2971
<a href="https://www.linkedin.com/in/aps08"><img src="https://img.shields.io/badge/LinkedIn-0077B5?style=for-the-badge&logo=linkedin&logoColor=white"></a>
3072
<a href="https://github.com/aps08"><img src="https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white"></a>
3173
<a href="https://www.youtube.com/channel/UC8biJQnoqm1s2FZ8LK90baA"><img src="https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white"></a>
3274
<a href="mailto:anoopprsingh@gmail.com"><img src="https://img.shields.io/badge/Gmail-D14836?style=for-the-badge&logo=gmail&logoColor=white"></a>
75+
<a href="https://t.me/aps080"><img src="https://img.shields.io/badge/Telegram-2CA5E0?style=for-the-badge&logo=telegram&logoColor=white"></a>
3376
</p>

docs/images/banner.png

55.1 KB
Loading

docs/images/secrets.png

42.1 KB
Loading

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Telethon==1.25.1
22
tweepy==4.10.1
3+
validator_collection==1.5.0

src/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .receiver import receiver
2+
from .sender import sender
3+
from .store import store

src/config.py

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

0 commit comments

Comments
 (0)