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:
- Open OI Chat, login and join the Animal Universe chat room at https://chat.openintents.org/#/room/#animal-univers-1:openintents.modular.im
- In a different tab, open Monster Planet at https://planet.friedger.de
- Add a subject to your kingdom and see a message about T&C for OI Chat
- Follow the link and agree to it
- Add another subject to your kingdom and see a notification from OI Chat that there was new message in the Animal Universe chat room
- In OI Chat type a message in that room
- 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 )