通过推送通知向自己发送 Matrix 消息

问题描述 投票:0回答:1

我正在开发一个 Java 应用程序,该应用程序在某些情况下向用户发送通知。

我的想法是提供Matrix作为另一个通知渠道,并使用用户自己的Matrix帐户发送消息。 (用户已经登录到也运行 Matrix 服务器的第三方网站。借助 SSO,我可以使用用户已存储的凭据登录 Matrix 服务器。)

虽然我可以使用Cosium/matrix-communication-client发送Matrix消息,但用户似乎没有收到任何推送通知(尽管消息被正确接收)。

我认为有两种可能的情况:

  1. Matrix 服务器不会通知用户自己发送的消息。
  2. 用户的 Matrix 客户端(在我的测试用例中为 Element)忽略有关用户自己发送的消息的通知。

这是真的吗?另外,我可以以任何方式规避这个吗?

请注意,我不想设置机器人帐户,因为这需要我托管服务器。

以下是创建 Matrix 房间并发送消息的示例代码:

public class Example {
  public static void main(String[] args) {
    MatrixResources matrix =
        MatrixResources.factory()
            .builder()
            .https()
            .hostname("matrix.example.org")
            .defaultPort()
            .usernamePassword("jdoe", "secret")
            .build();

    RoomResource room = matrix
        .rooms()
        .create(
            CreateRoomInput.builder()
                .name("Science")
                .roomAliasName("science")
                .topic("Anything about science")
                .build());
    
    room.sendMessage(Message.builder().body("Hello !").formattedBody("<b>Hello !</b>").build());
  }
}
java push-notification messenger matrix-org
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.