You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Eric install matrix-appservice-wechaty in his home server pulsar.im
Eric set up the app service bot name as @wechaty:pulsar.im, also reserved all the namespace that matching the regex ^[#!@]wechaty_.*$ to be controlled by this app service.
Eric enabled/registered the matrix-appservice-wechaty to his home server
Eric adds the wechaty bot @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
app service build a ghost user @wechaty_bob_wechat_id:pulsar.im
app service create a new room and invite @eric:pulsar.im and wechaty_bob_wechat_id:pulsar.im to that room
app service send message to the new room, and set the sender to be wechaty_bob_wechat_id:pulsar.im
Step 2. Bob send another Wechat message to Eric
all the same as step 1
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.
Does that the standard implementation for doing this?
Does there have other ways to do this?
What is the best practice to solve this problem?
The text was updated successfully, but these errors were encountered:
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:
matrix-appservice-bridge has a room store that stores data in a NeDB database. Most bridges based on matrix-appservice-bridge store their room mappings in there.
I'm guessing matrix-puppet-bridge has some generic solution too, but I haven't looked into it.
My bridges store all portal rooms in a single table. The table will generally have the remote user or group ID in one column, the remote receiver in another column and the Matrix room ID in a third column. The first two colums are the primary key and the MXID is a unique key.
Remote receiver for private chat portals means the remote user ID of the Matrix user who logged into the bridge. Since group chat portals in my bridges are shared between all users, I just set the receiver for group chats to the group chat's remote ID.
If you make a single-user bridge, you probably don't need the receiver column at all, only the remote group/user ID.
Theoretically you could also use Matrix as the database (e.g. store the mappings in Matrix account data), but I don't know of any bridges that do that.
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.
The text was updated successfully, but these errors were encountered: