mobilecoinofficial / forest

Enables a Forest of MobileCoin enabled SignalBots. Beta software, APIs may change!
MIT License
19 stars 12 forks source link

How to @ tag a user? #138

Closed dsernst closed 2 years ago

dsernst commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

Ok, makes sense.

Thank you! 🙏