Open huan opened 5 years ago
You'll need to store the mapping somewhere. The most common solution is to have some kind of database (NeDB, SQLite, Postgres, etc) to store all the rooms used by the bridge:
@tulir Thank you so much for answer my question in such a detail reply, appreciate it!
Recently I'm keeping thinking about what's the best practice for our app service to help matrix users to receive wechat message from wechat individual user.
The scenario is:
Background
matrix-appservice-wechaty
in his home serverpulsar.im
@wechaty:pulsar.im
, also reserved all the namespace that matching the regex^[#!@]wechaty_.*$
to be controlled by this app service.matrix-appservice-wechaty
to his home server@wechaty:pulsar.im
as his friend, and talk to the bot, get the Wechat login QR Code, then scan it to let the bot login the Wechat.After the above steps, the
matrix-appservice-wechaty
had logged in on behalf of Eric and will be ready to receive/send Wechat messages for Eric.The Problem
Let's say, Bob is a friend of Eric on Wechat
Step 1. Bob send a Wechat message to Eric
matrix-appservice-wechaty
received a message from Bob to Eric@wechaty_bob_wechat_id:pulsar.im
@eric:pulsar.im
andwechaty_bob_wechat_id:pulsar.im
to that roomwechaty_bob_wechat_id:pulsar.im
Step 2. Bob send another Wechat message to Eric
If so, we will create a new room for each new message in a conversation and end up with lots of new rooms with only one message in it.
One of the solutions would be: we save the room id when we create it for the first time, and then use it when there's any new message comes in the future.
The Question
I can use a store to map the wechat id to matrix room id, and whenever a wechat user sends a message to Eric, I'll try to find an existing matrix room id first. If it exists, I'll send the message via that room.