-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Обработка голосовых сообщений из вк в телеграм
- Loading branch information
1 parent
0dd67f5
commit 28d0fcf
Showing
5 changed files
with
33 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .chats import update_chat_info | ||
from .chats import update_chat_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from .files import get_file_from_url | ||
from .files import get_file_from_url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
from . import voices | ||
from . import messages |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from ..core import bot | ||
from vkbottle.user import Message | ||
from ...db import Sessions | ||
from ...db.models import Conversations | ||
from sqlalchemy import select | ||
from ...tg.core import bot as tg | ||
from ..utils import create_vk_link | ||
from ...utils import get_file_from_url | ||
|
||
|
||
@bot.on.message(attachment=["audio_message"]) | ||
async def on_audio_message(message: Message): | ||
async with Sessions() as session: | ||
bundle = await session.scalar( | ||
select(Conversations).where(Conversations.vk_id == message.peer_id) | ||
) | ||
if bundle: | ||
user_info = await bot.api.users.get(message.from_id) | ||
voice_file = await get_file_from_url( | ||
message.attachments[0].audio_message.link_ogg | ||
) | ||
|
||
await tg.send_voice( | ||
bundle.tg_id, | ||
voice_file, | ||
f"<a href='{create_vk_link(message.from_id)}'>{user_info[0].first_name} {user_info[0].last_name}</a>\n", | ||
parse_mode="html", | ||
) |