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

How to @ tag a user? #138

Closed
dsernst opened this issue Feb 23, 2022 · 2 comments
Closed

How to @ tag a user? #138

dsernst opened this issue Feb 23, 2022 · 2 comments

Comments

@dsernst
Copy link

dsernst commented Feb 23, 2022

I'm trying to figure out how tag the user who sent a message.

Like at the bottom of this example from Imogen:

image

I looked through https://github.com/mobilecoinofficial/forest/blob/main/imogen/imogen.py but not seeing anywhere in there that's doing it. It looks like Imogen's "your Imoge is done" logic is being handled in the redis callback somewhere, but didn't see where exactly.

I see Forest's Message.name and Message.source, and they're both giving me the correct string data, but just sticking @ in front of them didn't turn either into a user tag. E.g.

async def do_test(self, msg: Message) -> str:
    return f"@{msg.name} test"
@technillogue
Copy link
Contributor

Check out https://github.com/mobilecoinofficial/forest/blob/imogen-postgres/imogen/imogen.py#L248

To use this, you need to return None and send the message yourself, like

await self.send_message(None, "\N{Object Replacement Character} test", group=msg.group, mention=f"0:1:{msg.source}")

That mention argument is index of the replacement start:replacement length:identifier. You don't actually need to use , a space works, but that's what the official clients do. The client fills in "@name" with whatever that person has saved as that contact's name.

We might consider an actual Response class like aiohttp so you could return an object with a mention attribute instead of this setup.

@dsernst
Copy link
Author

dsernst commented Feb 24, 2022

Ok, makes sense.

Thank you! 🙏

@dsernst dsernst closed this as completed Feb 24, 2022
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

2 participants