Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add styling options to text #41

Open
mariopaolo opened this issue Dec 23, 2023 · 4 comments
Open

Add styling options to text #41

mariopaolo opened this issue Dec 23, 2023 · 4 comments

Comments

@mariopaolo
Copy link
Contributor

wanna start off saying this tool is amazing, I love it and use signalbot every day 😀

I would like to know if it's possible to support text styling in signalbot when sending messages.
I see signal-cli correctly registers the current text styling, here an example:

INFO:root:[Raw Message] {"envelope":{"source":"+XXXXXXXXXXXX", "sourceNumber":"+XXXXXXXXXXXX", "sourceUuid":"mySourceUuid", "sourceName":"user", "sourceDevice":1,"timestamp":1703357219298, "dataMessage": {"timestamp":1703357219298, "message":"MESSAGE", "expiresInSeconds":0, "viewOnce":false, "textStyles":[{"style":"ITALIC", "start":0, "length":5}], "groupInfo":{"groupId": "myGroupID", "type":"DELIVER"}}}, "account": "+YYYYYYYYYYYY"}
"textStyles":[{"style":"ITALIC", "start":0, "length":5}]

but I can't seem to be able to set it in signalbot and cant find any reference in bot.py

signalbot/signalbot/bot.py

Lines 174 to 204 in 71e09a1

async def send(
self,
receiver: str,
text: str,
base64_attachments: list = None,
quote_author: str = None,
quote_mentions: list = None,
quote_message: str = None,
quote_timestamp: str = None,
mentions: list = None,
listen: bool = False,
) -> int:
receiver = self._resolve_receiver(receiver)
resp = await self._signal.send(
receiver,
text,
base64_attachments=base64_attachments,
quote_author=quote_author,
quote_mentions=quote_mentions,
quote_message=quote_message,
quote_timestamp=quote_timestamp,
mentions=mentions,
)
resp_payload = await resp.json()
timestamp = resp_payload["timestamp"]
logging.info(f"[Bot] New message {timestamp} sent:\n{text}")
if listen:
logging.warning(f"[Bot] send(..., listen=True) is not supported anymore")
return timestamp

in signal-cli-rest-api there is a way to pass style to text in the API call
https://bbernhard.github.io/signal-cli-rest-api/#/Messages/post_v2_send

Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: italic text, bold text, strikethrough text.

is there a way to do the same in signalbot and I just can't find it, or this would need to be implemented?

thanks again for the amazing tool!

@mariopaolo mariopaolo changed the title Add Add styling options to text Dec 23, 2023
@filipre
Copy link
Owner

filipre commented Dec 25, 2023

I'm glad you like it! At the moment, styling is not supported, but it should be easy to add. Feel free to open a PR. I can also take a look a bit later.

@mariopaolo
Copy link
Contributor Author

hey @filipre I just created a pull request here #42
I tested it and it works but be gentle though, this is my first pull request 😅
if there is any problem let me know

@filipre
Copy link
Owner

filipre commented Dec 28, 2023

Thanks a lot! For anyone who wants to give it a test before the release, feel free to checkout #42 (comment)

@discernica
Copy link

(Nice to find the project, I am migrating my bot away from Telegram Bot)
I think I'm almost there with styling, but maybe I'm not understanding the implementation.

In the examples folder the "styles.py" file the text is entirely surrounded by the marker characters, but I'd like something like:

  • fixed-width some normal text something bold and now italic
    All in one message. I can't find where the styling is applied...? signalbot or signal-cli

Anyway, the results are strange and the styling is, well, off -- and seemingly random.
Does this mean the entire text message must be completely styled one-way?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants