Collaboration between apps (OI Chat/Messaging)

I updated OI Chat and the Monster Planet app such that they can talk to each other and with real users.

OI Chat allows to login apps (and users) with their identity address. There is one for the user and there is another one for the app when the user is logged in. Two addresses = two accounts on OI Chat (=matrix). Now, I implemented a simple API to receive and send messages between two apps of different users.

Before looking at the API give it a try:

  1. Open OI Chat, login and join the Animal Universe chat room at https://chat.openintents.org/#/room/#animal-univers-1:openintents.modular.im
  2. In a different tab, open Monster Planet at https://planet.friedger.de
  3. Add a subject to your kingdom and see a message about T&C for OI Chat
  4. Follow the link and agree to it
  5. Add another subject to your kingdom and see a notification from OI Chat that there was new message in the Animal Universe chat room
  6. In OI Chat type a message in that room
  7. See in Monster Planet the message below your profile picture.

OI Chat showing the automated message from Monster Kingdom


Monster Kingdom showing the user-typed message from OI Chat

What is in there code wise?
OI Chat is a fully chat client, that works as it is.
Monster Planet is a for of the Animal Kingdom tutorial with two additions:

  • after adding a subject, a message is sent
    const roomId = "!CjjvuECfgTSlVkzsEB:openintents.modular.im"
    this.userSessionChat.sendMessage(subject.username, roomId, content).then(
      result => {
        console.log("result ", result)
      }
  • on login a message listener is added
      this.userSessionChat.setOnMessageListener((event, room, toStartOfTimeline, removed, data) => {
        var msg = room.timeline[room.timeline.length - 1];        
        if (msg.event.type === "m.room.message" && msg.event.room_id === "!CjjvuECfgTSlVkzsEB:openintents.modular.im") {
          this.setState({msg:msg.event.content.body})
        }
      }
    })

UserSessionChat is a class that hides the communication with OI Chat/matrix and could be a separate package on top of blockstack.js. So it adds a dependency to matrix-js-sdk.
You can find the full code at https://github.com/friedger/animal-kingdom-1/blob/master/src/UserSessionChat.js

This works across apps, across users.

What is missing

  • Currently, apps use a predefined chat room to communicate. New chat rooms should be created if necessary to have 1:1 collaboration between apps or group collaboration between apps and users. (Just a question of using the matrix js API, coming soon)
  • Currently, the chat provider is hard coded as openintents.modular.im, all accounts are @:openintents.modular.im But it could be with different chat providers. There should be a way to change this in the blockstack browser and the DID API should publish the user’s settings. (Just a question of how messaging/inboxing should work on blockstack, to be discussed!)
  • There should be more than one chat provider out there. Feel free to run your own! (Just a question of money :slight_smile: )
4 Likes

Together with @yannael_leborgne.id we created a quick demo how to notify users from Blockstack apps using the matrix network:

4 Likes

Adding a text summary to the video:

  • Matrix is a good candidate for providing notifications between Blockstack apps and their users: Open source, secure, decentralised
  • Users log in to Matrix using OI Chat (an adaptation of the standard Riot client for Matrix that features a Blockstack login). OI Chat creates a Matrix ID that is the owner address of a user’s Blockstack ID (hence making sure that a user still owns their chat history even if their Blockstack ID changes over time)
  • Blockstack apps can create ‘rooms’ on the Matrix network, and invite Blockstack users thanks to their owner address. Users get notified that events related to their address happened in the Blockstack app ecosystem (either through desktop/smart phone notification, or mail, that can be configured in the OI Chat/Riot client)
  • Users can even send direct feedback to the app through the OI Chat app (see video above) !

Feedback on this welcome!

@friedger

Consider a simple file sharing app.
If user Alice shares a file with user Bob, can OI Chat be used to notify Bob that Alice has shared a file with them?

How difficult would it be to implement this notification workflow?

Would this require both Alice and Bob to be signed in to OI chat in advance?

I did something like that for inviting guests to calendars.

Alice needs to be logged in. Alice needs to create a matrix room and invite Bob. Alice can send any number of messages. Bob will receive the invitation as soon as he signed up and would see the messages.

OI Chat has reserved user names for all blockstack users, so no need for registration, just login.

1 Like

@friedger Thanks! :slight_smile: