Skip to main content

Lightweight library for working with Telegram Bot Api version 7.10 + Generate response on your answers

Project description

Ekogram

Ekogram - это легкая библиотека для работы с Telegram Bot API и нейросетями Она предоставляет простой и понятный интерфейс для отправки различных типов сообщений и обработки обновлений.

Библиотека похожа на telebot, но она более простая и подходит для разработки достаточно сложных проектов

Установка

Для Windows OS, Linux OS

pip install ekogram

Для Mac OS

pip3 install ekogram

Использование AI:

from ekogram import generate_chat_otvet, generate_voice_answer, generate_otvet, get_models

#Список всех доступных моделей(некоторые могут не работать на данное время, функция получает актуактуальный список моделей)
print(get_models())

messages = [{"role": "system", "content": "Answer in Russian. Don't use LaTeX, doing it with math symbols."},
            {"role": "user", "content": [{"type": "text", "text": "Что изображено на этом фото? реши уравнение"},
            {"type": "image_url", "image_url": {"url": "https://prezentacii.org/upload/cloud2/posts/2016-03/2/8/9/2893317685.gif"}}]}]
print(generate_otvet(prompt="Привет", model="openai-reasoning", seed=123, jsonMode=True, system="Answer in Russian. Don't use LaTeX, doing it with math symbols."))

print(generate_chat_otvet(messages=messages, model="openai", seed=123, jsonMode=False))

generate_voice_otvet(prompt="Привет", filename="voice", voice="nova")

Создание бота:

from ekogram import Bot, Markup, chat_gpt
import time

bot = Bot('You_Bot_Token')

@bot.message_handler(content_types=['new_chat_member'])
def hello_mention(message):
    new_member = message.new_chat_member.first_name
    new_id = message.new_chat_member.id
    chat_id = message.chat.id
    privet = chat_gpt("Привет")
    if new_id == bot.get_me().id:
        bot.reply_message(text=f"{privet}", mode="Markdown")
    else:
        bot.reply_message(chat_id, text=f"Привет [{str(new_member).replace('[', '').replace(']', '')}](tg://user?id={new_id})!", mode="Markdown")


@bot.message_handler(content_types=['left_chat_member'])
def godbye_mention(message):
    tot_name = message.left_chat_member.first_name
    tot_id = message.left_chat_member.id
    chat_id = message.chat.id
    bot.reply_message(chat_id, f"[{str(tot_name).replace('[', '').replace(']', '')}](tg://user?id={tot_id}) покинул(а) беседу", mode="Markdown")


@bot.message_handler(commands=['start'])
def start(message):
    buttons = [{'text': 'Кнопка 1', 'callback_data': '1'}, {'text': 'Кнопка 2', 'callback_data': '2'}, {'text': 'Кнопка 3', 'callback_data': '3'}]
    reply_markup = Markup.create_inline_keyboard(buttons, row_width=2)
    p = bot.reply_message(message.chat.id, f"Выберите кнопку {message.from_user.first_name}:", reply_markup=reply_markup)
    bot.edit_message_text(p.chat.id, message_id=p.message_id, text="Окей, шучу")
    bot.edit_message_reply_markup(p.chat.id, message_id=p.message_id, reply_markup=reply_markup)


@bot.message_handler(commands=['help'])
def help(message):
    buttonss = [{'text': 'Кнопка 1'}, {'text': 'Кнопка 2'}, {'text': 'Кнопка 3'}]
    reply_markup = Markup.create_reply_keyboard(buttonss, row_width=1)
    p = bot.reply_message(message.chat.id, "Кнопки:", reply_markup=reply_markup)
    time.sleep(3)
    bot.edit_message_text(message.chat.id, message_id=p.message_id, text="Удаляю кнопки", reply_markup=Markup.remove_reply_keyboard(True))


@bot.callback_query_handler(func=lambda call: True)
def handle_button_1(call):
    if call.data == '1':
        bot.answer_callback_query(call.id, text="Вы нажали кнопку 1!")
    elif call.data == '2':
        bot.answer_callback_query(call.id, text="Вы нажали кнопку 2!")
    elif call.data == '3':
        bot.answer_callback_query(call.id, text="Вы нажали кнопку 3!")

@bot.message_handler(content_types=['text'])
def ms_obrabotka(ms):
    chat_id = ms.chat.id
    message_id = ms.message_id
    if ms.text == 'Кнопка 1':
        bot.reply_message(chat_id, 'Вы нажали кнопку 1!', reply_to_message_id=message_id)
    if ms.text == 'Кнопка 2':
        bot.reply_message(chat_id, 'Вы нажали кнопку 2!', reply_to_message_id=message_id)
    if ms.text == 'Кнопка 3':
        bot.reply_message(chat_id, 'Вы нажали кнопку 3!', reply_to_message_id=message_id)
    if ms.text == 'Привет':
        bot.reply_message(chat_id, 'Привет, я бот!', reply_to_message_id=message_id)


@bot.message_handler(content_types=['photo'])
def handle_photo_message(message):
    chat_id = message.chat.id
    photo_id = message.photo[-1].file_id
    p = bot.get_file(photo_id)
    bot.download_file(p, p.file_path)
    bot.reply_photo(chat_id, photo=photo_id, reply_to_message_id=message.message_id, caption=f"`{photo_id}`", mode="Markdown")
    bot.delete_chat_photo(chat_id)


@bot.message_handler(content_types=['voice'])
def handle_voice_message(message):
    chat_id = message.chat.id
    voice = message.voice.file_id
    bot.reply_voice(chat_id, voice=voice, reply_to_message_id=message.message_id, caption=f"`{voice}`", mode="Markdown")


@bot.message_handler(content_types=['document'])
def handle_document_message(message):
    chat_id = message.chat.id
    document = message.document.file_id
    p = bot.get_file(document)
    bot.download_file(p, './document.txt')
    bot.reply_document(chat_id, document=open('./document.txt', 'rb'), reply_to_message_id=message.message_id, caption=f"`{document}`", mode="Markdown")

@bot.message_handler(content_types=['video'])
def handle_video_message(message):
    chat_id = message.chat.id
    video = message.video.file_id
    p = bot.get_file(video)
    bot.download_file(p, './video.mp4')
    bot.reply_video(chat_id, video=open('./video.mp4', 'rb'), reply_to_message_id=message.message_id, caption=f"`{video}`", mode="Markdown")


@bot.message_handler(content_types=['audio'])
def handle_audio_message(message):
    chat_id = message.chat.id
    audio = message.audio.file_id
    p = bot.get_file(audio)
    bot.download_file(p, './audio.mp3')
    bot.reply_audio(chat_id, audio=open('./audio.mp3', 'rb'), reply_to_message_id=message.message_id, caption=f"`{audio}`", mode="Markdown")


@bot.message_handler(content_types=['video_note'])
def handle_video_note_message(message):
    chat_id = message.chat.id
    video_note = message.video_note.file_id
    p = bot.get_file(video_note)
    bot.download_file(p, './video_note.mp4')
    bot.reply_video_note(chat_id, video_note=open('./video_note.mp4', 'rb'), reply_to_message_id=message.message_id, caption=f"`{video_note}`", mode="Markdown")


@bot.message_handler(content_types=['sticker'])
def handle_sticker_message(message):
    chat_id = message.chat.id
    sticker = message.sticker.file_id
    p = bot.get_file(sticker)
    bot.download_file(p, './sticker.webp')
    bot.reply_sticker(chat_id, sticker=open('./sticker.webp', 'rb'), reply_to_message_id=message.message_id)


@bot.message_handler(content_types=['animation'])
def handle_animation_message(message):
    chat_id = message.chat.id
    animation = message.animation.file_id
    p = bot.get_file(animation)
    bot.download_file(p, './animation.mp4')
    bot.reply_animation(chat_id, animation=open('./animation.mp4', 'rb'), reply_to_message_id=message.message_id)    


bot.polling()

Лицензия

Ekogram распространяется под лицензией MIT.

Контакты

Если у вас есть вопросы или предложения, пожалуйста, напишите мне: siriteamrs@gmail.com

Обратная связь

Если у вас есть еще вопросы, пожалуйста, дайте мне знать!

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

ekogram-0.13.5.tar.gz (29.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ekogram-0.13.5-py3-none-any.whl (27.1 kB view details)

Uploaded Python 3

File details

Details for the file ekogram-0.13.5.tar.gz.

File metadata

  • Download URL: ekogram-0.13.5.tar.gz
  • Upload date:
  • Size: 29.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ekogram-0.13.5.tar.gz
Algorithm Hash digest
SHA256 142b514fe28fdf345c1e1e3cc66aad14f7330ae71dc1e7812ce14be781dd5eb2
MD5 15994fbf9a605f285d889880e6194db1
BLAKE2b-256 252bbe5341918bba2403f9e9a97c8cc0731317d18c36752d66db7ef2e80315b5

See more details on using hashes here.

File details

Details for the file ekogram-0.13.5-py3-none-any.whl.

File metadata

  • Download URL: ekogram-0.13.5-py3-none-any.whl
  • Upload date:
  • Size: 27.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for ekogram-0.13.5-py3-none-any.whl
Algorithm Hash digest
SHA256 5b0e7a95bccf76f37421811c76be022ae98e575247fbd46beef05bed9a2d54f5
MD5 3770cf3fb77db28fd3a8093d2f4625e4
BLAKE2b-256 51176d3e6e84216660d2207cf37cb479c62335e85fff295459524a450ac00f5b

See more details on using hashes here.

Supported by

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