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.12.5.tar.gz (23.0 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.12.5-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for ekogram-0.12.5.tar.gz
Algorithm Hash digest
SHA256 3d4750bbc7e01b53cb60d8436b5ca1af1980434295983ce5140389692b799914
MD5 f16df0bb4a4df5315f952d953d5bff98
BLAKE2b-256 6f9c5baee28265c4ba76633f16bc8c20cbdd39b8c4d0bb8470ff03cc71f0ae3d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ekogram-0.12.5-py3-none-any.whl
  • Upload date:
  • Size: 20.3 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.12.5-py3-none-any.whl
Algorithm Hash digest
SHA256 6a3844f08c07e2f14a7b4fb20aed90e4b96a4c6721fa0c36f06c3ed5d08874b3
MD5 3642ed743eaf105b6d90a71abbd19e0a
BLAKE2b-256 6ab227b01be4c6ac7685ae2284334921dd28560dae7d9bbd2cecad2ba0ae5a78

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