Реализована отправка изображений в VK.
This commit is contained in:
parent
30cad14c43
commit
f162aceaf0
3 changed files with 20 additions and 6 deletions
|
|
@ -89,10 +89,15 @@ async def any_message_handler(message: Message):
|
||||||
answer: ai_agent.Message
|
answer: ai_agent.Message
|
||||||
success: bool
|
success: bool
|
||||||
answer, success = await utils.run_with_progress(
|
answer, success = await utils.run_with_progress(
|
||||||
partial(ai_agent.agent.get_group_chat_reply, bot_id, chat_id, ai_message, ai_fwd_messages),
|
partial(ai_agent.agent.get_group_chat_reply, bot_id, chat_id, ai_message, ai_fwd_messages),
|
||||||
partial(message.ctx_api.messages.set_activity, peer_id=chat_id, type='typing'),
|
partial(message.ctx_api.messages.set_activity, peer_id=chat_id, type='typing'),
|
||||||
interval=4)
|
interval=4)
|
||||||
|
|
||||||
|
if answer.image is not None:
|
||||||
|
photo = await upload_photo(answer.image, chat_id=chat_id, api=message.ctx_api)
|
||||||
|
answer_id = (await message.reply(answer.text, attachment=photo)).conversation_message_id
|
||||||
|
else:
|
||||||
|
answer_id = (await message.reply(answer.text)).conversation_message_id
|
||||||
|
|
||||||
answer_id = (await message.reply(answer.text)).conversation_message_id
|
|
||||||
if success:
|
if success:
|
||||||
ai_agent.agent.set_last_response_id(bot_id, chat_id, answer_id)
|
ai_agent.agent.set_last_response_id(bot_id, chat_id, answer_id)
|
||||||
|
|
|
||||||
|
|
@ -61,6 +61,11 @@ async def any_message_handler(message: Message):
|
||||||
partial(message.ctx_api.messages.set_activity, peer_id=chat_id, type='typing'),
|
partial(message.ctx_api.messages.set_activity, peer_id=chat_id, type='typing'),
|
||||||
interval=4)
|
interval=4)
|
||||||
|
|
||||||
answer_id = (await message.answer(answer.text)).message_id
|
if answer.image is not None:
|
||||||
|
photo = await upload_photo(answer.image, chat_id=chat_id, api=message.ctx_api)
|
||||||
|
answer_id = (await message.answer(answer.text, attachment=photo)).conversation_message_id
|
||||||
|
else:
|
||||||
|
answer_id = (await message.answer(answer.text)).message_id
|
||||||
|
|
||||||
if success:
|
if success:
|
||||||
ai_agent.agent.set_last_response_id(bot_id, chat_id, answer_id)
|
ai_agent.agent.set_last_response_id(bot_id, chat_id, answer_id)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from typing import List
|
||||||
|
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
|
||||||
from vkbottle import API
|
from vkbottle import API, PhotoMessageUploader
|
||||||
from vkbottle.bot import Message
|
from vkbottle.bot import Message
|
||||||
from vkbottle_types.codegen.objects import PhotosPhotoSizes
|
from vkbottle_types.codegen.objects import PhotosPhotoSizes
|
||||||
from vkbottle_types.objects import MessagesMessageAttachmentType
|
from vkbottle_types.objects import MessagesMessageAttachmentType
|
||||||
|
|
@ -63,3 +63,7 @@ async def create_ai_message(message: Message) -> ai_agent.Message:
|
||||||
if ai_message.text is None and ai_message.image is None:
|
if ai_message.text is None and ai_message.image is None:
|
||||||
raise utils.UnsupportedContentType()
|
raise utils.UnsupportedContentType()
|
||||||
return ai_message
|
return ai_message
|
||||||
|
|
||||||
|
|
||||||
|
async def upload_photo(image: bytes, chat_id: int, api: API) -> str:
|
||||||
|
return await PhotoMessageUploader(api).upload(file_source=image, peer_id=chat_id)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue