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

Retrieve com.beeper.bridge.identifiers from Beeper custom EventMessage #3

Open
hitchhooker opened this issue Sep 8, 2024 · 0 comments

Comments

@hitchhooker
Copy link
Contributor

Context:

We are working with a modified version of hungryserv (Matrix homeserver) that sends specific bridge source data via events. These events contain bridge information, such as identifiers for remote services (e.g., Twitter, WhatsApp), and are critical for our system to process correctly.

The source of this data appears in the event messages in the json payload, under the com.beeper.bridge.identifiers key (and other relevant fields like com.beeper.bridge.network, com.beeper.bridge.remote_id, etc.).

Issue:

We need to figure out how to properly access and read this data from the event messages sent to our Matrix client.

Currently, this data does not appear to be directly accessible from the Matrix SDK in our setup, probably because its for vanilla matrix homeserver and hungryserv is modified.

Relevant Event Data:

The MessageEvent Data contains additional details, such as the identifiers, network, remote_id, and service, that we are interested in:

{
  "messageType": "m.text",
  "body": {
    "body": "test"
  },
  "json": {
    "content": {
      "com.beeper.bridge.identifiers": ["twitter:hitchhooker"],
      "com.beeper.bridge.network": "twitter",
      "com.beeper.bridge.remote_id": "386457830",
      "com.beeper.bridge.service": "twitter"
    }
  }
}

Proposed Solution:

We would like to modify our Matrix SDK bot to properly handle and retrieve this com.beeper.bridge data from incoming event messages. Specifically, we need to parse and extract the following fields from the event content:

  • com.beeper.bridge.identifiers
  • com.beeper.bridge.network
  • com.beeper.bridge.remote_id
  • com.beeper.bridge.service

This can be done by extending the message handling logic in the SDK to access these custom fields in the event's JSON payload.

Steps to Implement:

  1. Parse custom event fields: We need to ensure that the SDK can parse and expose the com.beeper.bridge fields from the event's JSON content.
  2. Deserialize event content: Use a custom struct to deserialize the relevant fields from the event's content, which can then be accessed and logged or processed to verify source media of messages.

Here’s a suggested structure for the custom fields:

#[derive(Debug, Clone, Deserialize)]
struct BeeperBridgeContent {
    #[serde(rename = "com.beeper.bridge.identifiers")]
    pub identifiers: Option<Vec<String>>,
    #[serde(rename = "com.beeper.bridge.network")]
    pub network: Option<String>,
    #[serde(rename = "com.beeper.bridge.remote_id")]
    pub remote_id: Option<String>,
    #[serde(rename = "com.beeper.bridge.service")]
    pub service: Option<String>,
}

And integrate it into the message handling function as follows:

async fn on_room_message(e: OriginalSyncRoomMessageEvent, _room: Room) {
    if let MessageType::Text(text) = e.content.msgtype {
        // Handle normal message content
        info!("Received message from {}: {}", e.sender, text.body);

        // Deserialize Beeper-specific bridge data if available
        if let Some(extra_data) = e.content.get("com.beeper.bridge.identifiers") {
            if let Ok(bridge_content) = serde_json::from_value::<BeeperBridgeContent>(extra_data.clone()) {
                info!("Beeper bridge identifiers: {:?}", bridge_content.identifiers);
                info!("Beeper network: {:?}", bridge_content.network);
                info!("Beeper remote_id: {:?}", bridge_content.remote_id);
                info!("Beeper service: {:?}", bridge_content.service);
            }
        }
    }
}
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

1 participant