Do not send blockquote-formatted transcription when replying without a thread

This actually fixes 2 issues.

Fixes https://github.com/etkecc/baibot/issues/14
Fixes https://github.com/etkecc/baibot/issues/17

When people enable transcribe-only mode and the bot replies outside of a
thread, messages will no longer look like this: `> 🦻 Transcribed text`.

Instead, they will:

- look like this: `Transcribed text`

- get an emoji reaction (🦻) sent by the bot itself,
  to indicate that the message is a transcription

---------------------------------------

As https://github.com/etkecc/baibot/issues/14 discusses,
the `> 🦻` prefixing of messages also served the purpose of indicating
to the bot that this is not its own message, but rather something it
"heard" from a user.

Given that out-of-thread replies no longer include this, they could be
mistaken for bot messages.

Because transcribed messages are posted as notice messages, we can
easily tell them apart from regular text-generated messages by the bot
itself, so we can (and do) treat them differently.

Thankfully, the bot does not yet support building a text-generation
conversation from arbitrary messages (something discussed in
https://github.com/etkecc/baibot/issues/15), so these out-of-thread
replies having the wrong owner are not an issue for now.

If we do land support for this, we'll probably need to make the bot inspect such notice messages
posted by it, inspect their reactons and attribute them properly (🦻 -> user message).
This commit is contained in:
Slavi Pantaleev
2024-09-30 17:18:44 +03:00
parent 7a38216192
commit e6aa956423
3 changed files with 45 additions and 3 deletions

View File

@@ -5,12 +5,18 @@ use super::text::{block_quote, block_unquote};
/// Creates a text message which is based on transcribed audio.
/// This text message is prefixed with an emoji and blockquoted, to indicate that it is a transcription.
/// To reverse the process, use `parse_transcribed_message_text()`.
///
/// It should be noted that in certain cases (Transcribe-only mode), transcriptions are posted as regular notice messages which do not include
/// the `> 🦻` prefixing. That is, not every transcribed message will pass through here (intentionally).
pub fn create_transcribed_message_text(text: &str) -> String {
block_quote(&format!("{} {}", AgentPurpose::SpeechToText.emoji(), text))
}
/// Parses a transcribed message text, reversing the process done by `create_transcribed_message_text()`.
/// If the provided text string does not match the expected format, None is returned.
///
/// It should be noted that in certain cases (Transcribe-only mode), transcriptions are posted as regular notice messages which do not include
/// the `> 🦻` prefixing. This function will not handle these properly.
pub fn parse_transcribed_message_text(text: &str) -> Option<String> {
if !text.starts_with("> ") {
return None;