Skip to content

Python3 wrapper/library that simplifies telegram bot development. It supports both sync and asyncio methods of programming. Dive in and start making awesome bots!

License

Notifications You must be signed in to change notification settings

codingsett/telepota

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

Telepota - an actively maintained python3 wrapper for the telegram BOT API.

This project aims to simplify telegram bot development using higher level classes and functions which are easy to understand and implement. I took over development and maintenance from nickoala who was the author of this beautiful project.

Explore the docs »

Report Bug · Request Feature

Table of Contents

Getting Started

This project only supports python 3+, but for asyncio you are required to have python 3.5+

If you are previous telepot library user please uninstall it in your system before installing telepota. This is to prevent conflicts from happening while using this library.

Installation

  1. You can install this library using pip
pip install telepota --upgrade
  1. You can install this library using easy install
easy_install telepota --upgrade
  1. or you can install it from this repository
git clone https://github.com/codingsett/telepota
cd telepot
python setup.py install

Usage

Lets dive into the code so that you can get a feel of what to expect.

import sys
import time
import telepot
from telepot.loop import MessageLoop

#Namedtuple module contains different helper classes that help you pass the correct data required
#by telegram bot api
from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton

#this function catches all 'normal' messages from the bot. There are other helper functions such 
#on_poll_data that catches all reponses from actions performed on a poll
def on_chat_message(msg):
    #telepot glance method extracts some useful data that you may require in different sections.
    content_type, chat_type, chat_id = telepot.glance(msg)
    
    #keyboard made easily from a constructor class that we imported earlier.
    keyboard = InlineKeyboardMarkup(inline_keyboard=[
                   [InlineKeyboardButton(text='Press me', callback_data='press')],
               ])
    #This is how we send messages
    bot.sendMessage(chat_id, 'Use inline keyboard', reply_markup=keyboard)

#catches all inline_queries from the bot. Go to the documentation to read more.
def on_callback_query(msg):
    query_id, from_id, query_data = telepot.glance(msg, flavor='callback_query')
    print('Callback Query:', query_id, from_id, query_data)

    bot.answerCallbackQuery(query_id, text='Got it')

TOKEN = sys.argv[1]  # get token from command-line

#we pass the token from botfather to the bot instance.
bot = telepot.Bot(TOKEN)

#Messageloop initiates polling for the bot.
MessageLoop(bot, {'chat': on_chat_message,
                  'callback_query': on_callback_query}).run_as_thread()
print('Listening ...')

#make sure the bot runs forever.
while 1:
    time.sleep(10)

For more examples, please refer to the Examples Folder

Comparison

The following comparison of different libraries is purely subjective after using them for a while.

➖ means am not sure whats going on there because i dont have adequate information.

Framework Async Sync Runtime Documentation community active beginner-friendly
telepota Python3+ small
python-telegram-bot Python3+ large
pyTelegramBotAPI Python3+ medium
aiogram python3.7+ medium

Roadmap

  • Modify and improve test coverage.
  • Include github actions in the workflow.
  • Replace urllib with requests maybe.
  • Add more examples for new methods included for BOT API.
  • Update telepot to latest BOT API version.

Contributing

All contributions are welcome and appreciated. A few guidelines you need to follow before contributing:

  1. Document your code(for self documenting code there is no need for unnecessary comments).
  2. Make sure the tests run properly.
  3. Create a pull request.

I will update this guide with more details in order to provide a good base structure.

License

Distributed under the MIT License. See LICENSE for more information.

Acknowledgements

I would like to thank the original author nickoala for making this framework. I have been using it for 3yrs+ without any changes.

About

Python3 wrapper/library that simplifies telegram bot development. It supports both sync and asyncio methods of programming. Dive in and start making awesome bots!

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages