Skip to content
/ Q4T Public template

Post scheduled quizzes on Telegram using a list of questions from Google Sheets

License

Notifications You must be signed in to change notification settings

paramt/Q4T

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📝 Scheduled Quizzes for Telegram

Post scheduled quizzes on Telegram using a list of questions from Google Sheets

🔌 Set up

  1. Click the Use this template button on GitHub and create a private repository
  2. Create a Telegram bot
    • Follow these instructions to generate a token
    • Add your token to config.py
    • Add the bot to your channel or group and promote it to administrator
  3. Connect to Google Sheets
    • Go to Google Developer Console and create a new project
    • Click + ENABLE APIS AND SERVICES and enable the "Drive API" as well as the "Sheets API"
    • Navigate to "APIs and Services" > "Credentials"
    • Click + CREATE CREDENTIALS and select "Service account"
    • Fill in the required fields, press CREATE, CONTINUE, and on the last step click + CREATE KEY to download a JSON file
    • Upload the JSON file at the root of your GitHub repo and add the filename to the credentials variable in config.py
    • Copy the Google sheet template and share it with the email address found in client_email in the JSON file
  4. Configure options in config.py
Option Description Type Example
spreadsheet Required - The name of your Google sheet String Q4T Template
channel Required - The unique identifier of your chat or the username of your channel (the part after t.me/ in the invite URL) String q4t_playground
loop Whether of not the bot should loop through the questions if all the questions have been exhausted Boolean True
anonymous Whether to keep the responses anonymous (Note: this must be set to True for channels) Boolean True

⚠️ Make sure your repository is private, because your Google credentials and Telegram token is sensitive information.

🖥️ Usage

You can add as many question/answer sets in your Google sheet as you want. You can also send an image alongside each question by providing the link to the image. The image will be sent immediately before the question. Everytime the script is run, it will send a quiz to the target chat or channel and increment the index in the index sheet. You can keep adding more question/answer sets indefinitely.

Run at scheduled interval

To send quizzes at a certain interval, run src/main.py at the specific interval. The recommended way to do this is to use GitHub Actions. Here is a sample workflow you can put in .github/workflows/main.yml to send a quiz every day:

name: Send quiz
on:
  schedule:
  - cron: '0 0 * * *'

jobs:
  run:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - uses: actions/setup-python@v1
      with:
        python-version: '>=3.6'
    - name: Install dependencies
      run: pip install -r requirements.txt

    - name: Send quiz
      run: python src/main.py

Reset

To reset the spreadsheet, simply run reset.py. This will remove all questions and set the index to 2.

About

Post scheduled quizzes on Telegram using a list of questions from Google Sheets

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages