Skip to main content

Speed telegram api libraly

Project description

bonfire

bonfire this framework for Telegram Bot API built on flask and requests
Ukrainian launge translate -> click
instaling

git clone https://github.com/Help-urself/bonfire

or

pip install -i https://test.pypi.org/simple/ bonfire-tg-libraly
pip install bonfire-tg-libraly

Examples

Click

1.install interceptor

  • install ngrok and start the server according to the instructions on the website.
  • set webhook https://api.telegram.org/botTOKEN/setWebhook?url=you url ngrok/hosting url

Simple send_message request

#git clone

import requests
from flask import Flask
import os
import sys
sys.path.append(os.path.abspath('you path to bonfire'))
from bonfiree.methods import *
from bonfiree.Bot import *


app = Flask(__name__)
token = "..."#token


@bot.handler
def start():  
    if msg.text == "/start": 
     send_message(token,chat_id=msg.chat_id,text=f"Hello {msg.author_username},is test bot")#send message

@commands(app)
def main():
 global msg
 msg=message(request.get_json())#message handler
 start()#start function start


 return Response('OK', status=200)#return status ok to cmd
if __name__ == '__main__':
       run(app)

       """set-webhook - > https://api.telegram.org/botTOKEN/setWebhook?url=URL"""
#pip install

import requests
from flask import Flask
from bonfiree.methods import *
from bonfiree.Bot import *


app = Flask(__name__)
token = "..."#token


@bot.handler
def start():  
    if msg.text == "/start": 
     send_message(token,chat_id=msg.chat_id,text=f"Hello {msg.author_username},is test bot")#send message

@commands(app)
def main():
 global msg
 msg=message(request.get_json())#message handler
 start()#start function start


 return Response('OK', status=200)#return status ok to cmd
if __name__ == '__main__':
       run(app)

       """set-webhook - > https://api.telegram.org/botTOKEN/setWebhook?url=URL"""

Documentation (in development)

Click

functions

send_message

def send_message(token,chat_id,text):

-token - keyword where you store the token
-chat_id - you can use your chat id or use the msg.chat_id method
-text - your message text
-parse_mode( Optional ) - parse mode in HTML (optional)

example
msg=message(request.get_json())

#without parse_mode
send_message(token=bot,chat_id=msg.chat_id,text=f'hello :)')
#with parse_mode
send_message(token=bot,chat_id=msg.chat_id,text=f'<b>hello :)<b>',parse_mode='HTML') #make text bold


reply_message

def reply_message(token,chat_id,msg_id,text,parse_mode):

-token - keyword where you store the token
-chat_id - you can use your chat id or use the msg.chat_id method
-text - your message text
-msg_id - you can use your message id or use the msg.id method
-parse_mode( Optional ) - parse mode in HTML (optional)

example
 msg=message(request.get_json())
#without parse_mode
reply_message(token,msg_id=msg.id,chat_id=msg.chat_id,text="reply message ._.")
#with parse_mode
reply_message(token,msg_id=msg.id,chat_id=msg.chat_id,text="<b>reply message is bold .-.</b>",parse_mode="HTML")#make text bold


send_sticker

def send_sticker(token,chat_id,sticker):

-token - keyword where you store the token
-chat_id - you can use your chat id or use the msg.chat_id method
-sticker -unique sticker key, you can get it from idstickerbot

example
send_sticker(token,chat_id=msg.chat_id,sticker="CAACAgIAAxkBAAEGdwNjd-IwPaLBzeqJW1DJvDLGnYOJpwACQBMAAvZDSUjqTxpxhtdlhisE")


delete_message

def delete_message(token,chat_id,msg_id):

-token - keyword where you store the token
-chat_id - you can use your chat id or use the msg.chat_id method
-msg_id - you can use your message id or use the msg.id method

example
delete_message(token,msg_id=msg.id,chat_id=msg.chat_id) #this code will only work in a private chat, so that it would work for the bot to have the right to delete messages or replace message_id with reply_message_id, you can find an example in the folder example->delete_message.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bonfire_tg-1.0.7a0.tar.gz (7.1 kB view hashes)

Uploaded Source

Built Distribution

bonfire_tg-1.0.7a0-py3-none-any.whl (9.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page