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

The best practice for bridge direct message from Wechaty to Matrix users #2

Open
huan opened this issue Jun 6, 2019 · 2 comments
Open
Labels
question Further information is requested

Comments

@huan
Copy link
Member

huan commented Jun 6, 2019

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

  1. Eric install matrix-appservice-wechaty in his home server pulsar.im
  2. 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.
  3. Eric enabled/registered the matrix-appservice-wechaty to his home server
  4. 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

  1. matrix-appservice-wechaty received a message from Bob to Eric
  2. app service build a ghost user @wechaty_bob_wechat_id:pulsar.im
  3. app service create a new room and invite @eric:pulsar.im and wechaty_bob_wechat_id:pulsar.im to that room
  4. 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
  1. 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.

  1. Does that the standard implementation for doing this?
  2. Does there have other ways to do this?
  3. What is the best practice to solve this problem?
@tulir
Copy link

tulir commented Jun 6, 2019

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.

@huan huan added the question Further information is requested label Jun 6, 2019
@huan
Copy link
Member Author

huan commented Jun 6, 2019

@tulir Thank you so much for answer my question in such a detail reply, appreciate it!

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

No branches or pull requests

2 participants