Building Group Chats with XMTP UX
Urbe Campus ETHCC Edition 2024 · August 2024 · 52:27
Fabrizio Guespe of Ephemera presents XMTP, the open source, end-to-end encrypted decentralized messaging protocol, and its new MLS-based group chats with forward secrecy and post-compromise security, soon to be owned by node operators. He argues that apps and mini apps are the next layer for developers to build on, as Farcaster showed, and shows how to build on top of XMTP groups.
Speakers
Topics
From Urbe Campus ETHCC Edition 2024, hosted by Urbe.eth.
Transcript
[Music] it's a Fab from ephemera so we are building XMP XMP is a decentralized messaging protocol soon to be decentralized right now is the it's open source it's end to end encrypted and we just released group chats and group chats is based on MLS encryption and it's like a threee long um Milestone that we just achieved and this is the first time that you have like a truly scalable open source n to encrypted and these uh group chats that are going to be soon to be owned by the community and the node operators running the servers so you may have seen the
announcement earlier this week group chats uh because they use MLS they have some almost every security measurement you can think of so you have this thing called forward secrecy so the idea is that every every time you send a m message the encryption key the pair of keys change the private key Chang so what happens here is that if an attacker gets access to one of the keys because it has this forward secrecy property it's not going to be able to access the pass messages and there is another thing called post compromise is not going to be able also to use that key for continue to send messages so even if it's hacked the attacker only gets access to the current message and
device that it has access but it cannot send any more messages nor access history so this is These are 3D secure group chats so now we have the groups it's open source you can go build inboxes yes but that's hard and we are thinking about what else you can build on top of groups and on top of apps so who's uh who knows about frames who has built frames and who has built Bots who has experiened building Bots uh who has experience like interacting with telegram mini apps yeah yeah you know okay so we can think of um telegram mini apps as this uh so-called app layer so what happened with workast as we've seen
is that you can build on top of apps so in the past if you were a developer 10 years ago and you wanted to build on top of Facebook or Twitter it was possible for some time you may heard about this history about the Singa company that was creating games farm bill on top of Facebook and then they got like racked right so they lose their business and then all the apis were shut down and there was no innovation on top of messaging nor um social for like a decade and that was really frustrating for us for de we had to build our own like CEO strategies to make the website grow and all the s businesses were like funded by million dollar startups from San Francisco so uh we never really got
a chance so I think this time with web free and with everything that is happening with uh in the app layer now simple developers like JavaScript developers web developers frontend developers are going to have real opportunities to build on top of these apps and to access their distribution so as devs we want to access users we don't want to be creating like full landing pages we don't want to be investing in Co Google ads that market is saturated doesn't work anymore so we want to access the distribution of apps like warcast apps on top of lens and apps on top of xntp so building on top of groups I'm going to be showing something that is not available yet it's uh Converse groups and Converse groups is it's on
test flag right now but the idea is that uh it's using our SDK from from it's called the MLS client so I'm going to there is a quick start already available in our in index MVP repos so this quick start is interacting with API and in this case I'm going to run an example we are going to can zoom yeah is that good yes okay so very basic example uh we are going to create the wallet this is going to create identity in XMP so XMP is messaging between wallets But first you
need to sign up for the first time so if you have a enss address and I send you a message you're not going to receive it unless you have signed up for the first time to XMP then if you if you did you're going to receive the message on your XMP prefer inbox which could be coinbase or Commerce and because groups uses B free and is based on MLS encryption uh this is also called B free identity so this doesn't work today in Converse B2 nor coinbase so this is only working for now in Converse test flight um so if we run this example is using a private key a test private key I have here is creating an inbox ID in in in
identity B free you can assign multiple wallets to the same identity so it's you're not only you are not forced to use the same wallet you can um associate or delegate your conversations and your messages to multiple wallets so in this case my inbox ID was created from my initial wallet but now I can add more wallets to this inbox ID and I can remove them and it's very flexible in terms of how many wallets you can have then because everything is encrypted we are always going to be depending on a local cage cage in our conversations because it needs to be decoded and encoded on the client so there is also some some details around
if like if you change devices today your conversations are not going to be available able in in the other app because everything was decrypted at the uh in your previous device and yeah we losing we using beam wallet you just need to create a wallet with beam add a signature this is this was also not needed in in B2 and in this case we started the stream of messages and well there were no conversations created because I didn't send any message so now if we grab this SD um this Library MLS MLS client and we think on of how we can if
we have an app that uses his client uh well in this case is a react NK how can we build experiences on top of groups how come uh imagine when this app gets to the millions of users right and we want to interact with those millions of users how we do that so we are we are developing this this usdk called message kit and message kit is a is a way to interface with the app it's like a way for creating telegram Bots the telegram Bots version of of telegram for web free and built on top of xmtv so it also has a cool CLA command
I'm I don't know if you know box this library but they don't allow for Boon here but I'm going to to do b anyway so message kit comes with three examples so the GM example the one to one and the group so let's say we start with the GM okay again we always need to put the
private key that we want to use and uh in this case we are in Dev Network so that do not need to change let's use this one no can do boon and B so the if there was no private key this will create random
key random private key we can save it for later and it generates a wet address so and this is all you need to create like an XMP identity so if I go to uh this is Converse in verion in maos version so if I create a new group with this address because it's it's just signed up to XMP it's it's not going to uh display it it name in in the app okay so I can add description I can add name and latly late later I can add more members so this is a group chat of two people people but I can say hi and the B is going to reply
GM now because it's in test flight the stream is failing we need to get that stream started let's also try modile for okay uh
so this is the message kit structure of a bot it has a stream that is listening to new messages that come from a group and then it has the so-called context and context includes uh many components and parameters so in this case I'm not using them but you we can know the the center of the message and the content and everything is under development so if you like even if you have cool ideas uh please tell me but because I started with how can we build cool use cases this is what happen like this structure of of SDK um just thinking about what can we do in terms of use
cases and even business mods so in this case I'm just replying GM and that's all that is and it's using [Music] in uh the message sheet SDK so that's easy enough let's go to the this the message message kit monor repo and in the monor repo I also have the the examples the GM example but I have two examples more the a one to one so it's a bot for handling subscriptions so I can say uh Jam one what thanks
and this is the the group example and the group example it's it was a a way to talk about all these use cases so we are going to see how we can create AI agents how we can create a group chat that handles tipping how we can handle betting in a group chat uh play games through frames handle transactions like sending money to other uh members of the group split payments this is a a cool example of how to use a iion for splitting a dinner Bill and admin commands how to add members remove members change the group name and this is all we are going to be using like the
concepts of uh All The Primitives that are inside a group chat so you can receive messages this message can be text if it's text you shall receive stream string if you receive a reaction you get the Emoji in Unicode it's also going to be a string sometimes you want to reply so the rep uh a reply has Associated another message so you get the ID of the message that is replying to commands we build is very is primitive for now but kind of works um how you can use slash commands and send parameters and those param to be pared
into an into a Shon aray and how to send images and then listen to membership updates and metadata so let's try let's go into the group example so this group has many commands uh which reference all the use cases which have seen so the tiping bot is handling the tip command SLP and receives three parameters users amount and
tokens and I can also specify what type of parameter is that if it's a username it's going to return me an array of users who are mentioned with yet and the amount is also a number so let's try this one this is the L group L group is associated with this wet address so I can say um tip Alex 20 and you can see it just receive the message
tip it was a text and also recognize how many tokens I'm sending so what's happening here is that the index file which is more complex than the GM but still is this is all the all all the code that uh from the index file so what's happening here is I'm receiving a message this message has a type ID that could be text reactions uh replies and if it's uh if it's text I'm sending it to the test Handler and in the test Handler if it starts with at this means it's an AI agent and if it starts with Slash it's a
traditional command so so in this case I'm declaring those commands here this is a command Handler and I'm saying if it's tip command use the Tipping Handler and the Tipping Handler is is another file in the Handler folder so I go to tipping and this is the tiping B is not using d uh but it's just D is just apis so D is a concept could be any
token so what's happening here is that it's if it has received text and this text starts with tip then we are going to get information about its parameters so we can log this now let's get the parameters of this command I can send to two users let's send 100 so you get the type ID text you get
the array of usernames this is related to the to the username field in the when I declare the commands and it's also passing the amount into a number so it's very straightforward very simple we can also see the addresses of the user the inbox ID this is from XMP and the main address users are going to have like a main address associated with their profile and then the reply is 200 tokens the same works this same Handler is also handling reactions so I can
um or replies I can reply D 100 d this is a different type of logic if it's if it's a reply so if if it's type reply and I have an includ D this is just if you literally need to to type D in the string then it knows attracts the number with Rex and it just after that it sends you a notification that how many tokens we received so that's an intro to commands and these commands can generate
frames so if I if we create if we say if we do the same thing with a game command I want to place slots this receives the parameter type command declare in the commands this is the game bot and you only accepts wle slot and help so if I also want to do game help it tells me about the available games and is of type string there are like four or five types right
now now let's go into Ani agent nice sorry yeah if is is it possible to show all the available commands in like yeah there is a default help command okay and this gives me everything that's inside this bot it's just a string it's it's not generated like automatically for now but I'm handling the help command I think it was see another please that has functionality
right it's just um was me yeah I was in the command Handler so instead of creating a whole Handler for the help command I just created the H Handler inside this declaration so what it does is has access to so it's not is Parts automatically from the command dots file so grabs all the commands declared by the user and then they are presented nicely in a string for users to use and
this is uh maybe you know Telegram they have this command pet so if I'm in Telegram and I I I I I I type a slash command triggers all the possibilities so this is the the direction we want to go I we also having doubts about like this is pre AI so slash commands maybe they they are good like in the past maybe they are not the best thing to do I'm moving forward still a lot to explore um but they are definitely like very fun to use commands are cool yeah like we can have we can add a
user admin add I think I think Alex is already in the group admin remove Alex right so I'm not an admin so [Music] the the L group bot okay it's not I should have an option here to make an ad we can see later but yeah some things about the groups are require admin
privileges and if you go to this is like the group SDK literally from xntp that you have access through message kit so when you get the conversation in the context of every message this conversation is the group itself and is interacting with the SDK of uh xmt so we can get the name of the group we can update the name get the description update the description and then we can also add members remove members and load all the messages from from the group chat okay and now let's go into agents this is
um like how how can you declare agents as commands you can have multiple commands and you can also have multiple agents and those start with the ad symbol so in this case we are just using agent and agent is she gbt 40 powered so I can say hi hello how are you today um and the agent knows all this help command is already filled into the agent so it knows what to do so let's play a game now the agent goes to the commands and understands intent and uses commands
to return you again in this case a random one so what's happening here is we have a system prompt that uses um gbt apis the I'm using the middleware from open AI just the chat completition API this is it and I'm sending the system prompt and the system prompt is this one like your are helpful agent that LE inside the web free messaging group these are the users of the group you can access the members from the context you can access all the commands
from the context so these are the members these are the commands uh if you ask if you are ask about ches make web free shes about devs and then if a user ask about the per Performing an action and you think a command could help answer directly with the command and nothing else and popul the command with correct or random values but never return it like a as part of like a V placeholder text unless I'm explicit so if I say agent explain me how to play game with commands now I'm being explicit so it's going to Ideal is going to skip yeah it's going to skip performing
the the action and it's just going to explain me how to use uh commands and kind of like using markdown but I don't know markdown is cool could be cool to have markdown inside the app telegram renders the the commands with they highlight the commands let me see if yeah like you can click commands and and copy paste them uh so something like that could be cool so yeah by this is like a default agent
that has access to all the commands you can also it can also perform actions like send agent send one e to Alex so knows the address of Alex knows the commands on how to send one e knows about base frame base frame one of the one of the frames we develop with or urbe um so all the parameters inside the URL and that's how you can generate a frame through AI commands and then frame and another cool example if we take a picture of a dinner
bill now this is split payments use case on top of groups let's see what's happening here this is receiving an image and is sent to open AI openi checks that it's a dinner Bill if it's not the dinner Bill does nothing if it is splits the payment into the members of the group so the code is super simple this is the system prompt for vision so if it's type ID remote attachment the message handles the decryption and we have the the file in base 64 so this is the this the bill of the
restaurant dinner return the total if you can't find the total so first I'm asking to return the total and once I have the total I use GPT text to perform the the split and show the frame free lines of system prompt and now you have split wise built on top of groups this is how simple it is and the instructions like if you receive the totals send one frame to each user and it can answer also in a m message stream doesn't need to be everything in one message questions so far I have a
couple first one around the identity like the you mentioned that you are allowing users to connect different wallets to the same identity yeah but this means that X MTP will create a new identity for the user somehow so you will have a usern name that is TI to your xtp identity and then you connect addresses similar to yeah yeah because another naming system that has not been decided yet um but is the most possible thing is to have a like a or XMP naming system or each app to have its own system uh maybe
even it will be good to use ens but probably at first well comers has its own name system coinbase has its own name system too so a way to put them together and then the other one is around the the agent so to call an agent I have to use hot agent or H something else but what if I want to mention somebody in the group then isn't the this definition of an agent limiting the other other features for the app because if we use hat then we can mention people in the group and we're missing a
something that we already use on WhatsApp yeah no that's a good question um that will break everything now we have also doubts about uh multiple Bots maybe overlapping SL commands so what happens there so one idea is to uh let's say this is not multibot ready yet but if I do let's say I want to do send command on the you know bot one and then I put the parameters so you specify the bot inside the command that could be one possibility and then the the agent the agent username yeah it should not overlap with
with any of the group chat usernames we need to find a way to prevent that I think like a way to do that is maybe considering the agent another a separate bot that is part of the group so it's compatible with mentioning because you're but you're not mentioning a an actual person you're mentioning the which has its own address and its own code running behind the scen so not overlapping with SL commands but separating it and considering it as a member of the group so in this case it's called uh L group the B is called L group right that's the handle of the the bot yeah so you're saying just at L group should
trigger the yeah or like let's say that I and I call it and everybody can invite it in the group M and they can mention that s and that prob reply after elaborating yeah that would be like by default that's great idea now if I want to inside the B if I want to declare [Music] two you know could even be like instead of this just doing AI let's say or SL agent and then you like you you declare them like SL commands maybe you you don't need to
make a distinction there yeah that's those are things that we need to think about um like even yeah you can even default to to the B username and then you can do whatever you want inside the like like what let me check that one yeah yeah they both are users and you can just you mention user and you if it's about response
Trigg yeah that's going to well in this case and about the comms overlap also taking inspiration from Discord when you type slash you can see all the commands that are available in the group from the different Bots and and you can select so that if there are overlaps you can pick the one that you want for example we have you our Discord we have two Bots that allow po Creation with the same commands and we usually select one of the two the one that we prer well some things um because message kit is open
source right so ideally is going to be used by any app that uses uh message kit and x and XMP so it could be used is going to be available in coin wallet let's say so everything this is very opinionated at the client level so so it's like finding the right balance between making it easy for inboxes making it easy for users to use them for developers and um yeah how you orchestrate the whole thing uh with minimum front end like standards and development so yeah it's about finding the the right balance like even this this tab this command
pet like it's a hard thing to do like in front end yeah yeah to so it's like we need to find this easiest way to to make this work but yeah multi Bots multi commands that's super cool yeah they have even they even have a tab for each bot but then there should be something that buil in in Discord that allows when you select the like that command or that box that should be a way for the message to be directed exactly to the B so maybe a mention I don't know yeah slash a mention yeah well in this case this
default commands Discord knows about them so yeah this is cool yeah I used to do I used to have um I I learned crypto because of a infinity and you to I lost all my money too do you lost all my all your money uh so but at the time I was running a gaming guild uh in Venezuela of about at the peak of the bull market we were there were 350 players playing from Venezuela we had like a whole management structure uh teachers and
investors and everything and everything was managed by a Discord bot the onboarding of users the split payments uh like week payments the firing of low performance users too everything was done through discore so I love discore and it's it's been really the inspiration for all of this um I don't have the same opinion of telegram like I don't know I didn't I still haven't found found like a cool telegram bot but um yeah have you heard about cool mini apps in Telegram uh trading BS trading mods yeah useful yeah yeah those are big you lose a bit
of security at the user level but they are pretty fast and to buy and sell but they they forward you to they give you URLs you delegate the wallet to the bo yes and then uh so you lose most of them store your keys mhm so it's you L own security basically but uh if you create a new wallet you deposit some funds and you delegate this wallet to the boat then you have access to and this is a telegram wallet uh I think uh it's mini up
wallet that's store your keys and then uh use your keys but I can create like a metamask wallet and then put that key into tegram mod I think so yeah so inmp you you don't need that part no like ideally it's not going we are not going to have custodial wallets like you should interact directly with the like you should accept I guess yeah the TR mode is just like goes yeah is almost for session Keys is a session Keys use case I yeah because for for example in this um if I go to swap one if to
die so in this case if the bot had my private GE it could just swap it I guess yeah right so what's going to happen there I don't know in this case it's going to in this case what is going to do in this case it's going to take me to K wallet to make the swap yeah you bu it yeah yeah we we don't have transactions yet support uh but we are going to start default into coinbase wallet okay because building a wallet is hard in the app and also it's going to get us in a lot of problems with Apple
so we're going to try to take our time there [Music] um when areactions uh when will transactions be supported like Al we have any idea well it's uh it's going to be part of the first public test flight so we are not we are not launching without that yeah but right now like while building this app we are finding a lot of bags in groups in this Decay so it's like a huge uh groups is a huge effort to make it like reliable to work for the strings to
work so uh as soon as we get that like to really really work then we start with the cool features yeah and then we we are with this open frames through message kit so if you want to build frames on on in this case on for example apps like comerse you will you will need to use open frames and they reference reference to uh the frame the three main Frameworks and some tutorials about how to use transactions and so on so the idea here is
to like if you go to xtp you're not going to hear about Bots nor frames that's not from the protocol that's uh is going to be inside message kit if you're build if you want to build mini apps you go to message kit and you learn how to build Bots and how to build frames through open frames and maybe we we start also shipping new features to open frames like for example we were talking about no image frames or just buttons like the telegram Bots yeah is basically no image frame with more buttons right right so maybe we can create that very easily for frames like 10 buttons and that's it I hope so yeah uh it unlocks a lot of functionality it
should be rendered by the app and then I guess it's going to be some I don't know the buttons is very strict in four yeah to declare four you cannot but up to four but that restriction is put by warcast the cks are like you can add more buttons I don't know actually never think about that because it's an array FR yes so I think depends on the library yeah it's one okay but then they are just HTML Mets so
yeah yeah this one this one is text and two buttons but like having more than four buttons maybe makes the app the mini app too too complex so I think it's a limitation that also helps with user experience yeah like five six buttons simple yeah if you have like Min up it's different if you have a message is four buttons but if you open a new model a new screen having more B is like lot more something
like that yeah it could be could be interesting to try it out so for example also uh David was talking about building an app yeah he said something about that because if he thinks of a new FRS feature he's there is no way for him to try it out or like there's no way to implement it right so now everybody's building abs but even the Frameworks but for example in in this case let's say we are comers and comerce is going to be uh is going to be making decisions on which features are native which features are available to devs and is this uh
constant fight between like if a Dev gets too successful then the app is going to uh steal that feature and make it native so how do you build an app that doesn't do that and it's like you know not developer first but equal opportunities for Dev and for the app itself like user's choice you know um so that's going to be challenging and uh yeah and then then app directory is coming
so this is very early stages we have some of the open frames be build already some of the group some of the one onone one to one Bots we already built and now it's time for the group chat bots so ideally this is going to grow bigger and bigger and if you go to Discord actually now they have this um they just went all in into building mini apps Discord build the landing is super cool and you can go to the app directory and anybody can add you to a
group or just your allowed contacts or anybody can add you to a group chat anybody can be added to the group that's the question yeah um maybe because in Discord you have like a lot of verification steps before accessing Discord server or something what do you think about that uh layer of uh yeah that there is also is in it's not here but I have another section it's called access but we haven't decided yet but the idea is that uh message kit is also going to be handling access so you get the address of the one that is requesting and if the bot the admin and let's say you need to
hold 100 e to join the group or let's say half an if um and and then the the B says okay he's holding I don't know goes to AAC checks your balance in whatever and says he's good and you're in okay I I then BP is going to have something like that okay okay yeah also needs to be like needs to be a way to make it that it's not uh enforcing in the app like a way for developers to use it and that it works in all apps so the app needs to if you like everything needs to be you need to add a bot so that's not the most convenient thing but and this is like in terms of
features it's going to allow for a lot of experimentation and also if you don't have if you don't add the Bots the group is fully private right it's really secure it's open source you can trust it once you at the boat you need to trust the vat so it's another layer of trust um and if the but at least you know who is watching if you know if if the app is watching and does its own thing then you know it's an extra layer now you have the app listening and you have the both listening and can you turn off the Open Eye chat listening to the admin to the admin yeah in this case I choose to integrate open ey in this bot
but is this is not part of the CK this is outside yeah it's just this is part of the group and it's completely optional yeah I was thinking about putting shbt inside the DK you know some I like I I haven't seen anything like this anywhere but makes sense to have ai as part of the CK maybe something to think about and this one so I can I can create a bet now about uh
will there be um spam inbox also for groups so let's say convers now you have a the requests main inbox or the spam inbox still receiving messages but at least the client is easily categorizing them as spam will there be something similar for groups yeah that's live already let me see if the message gets sent sorry is this your
private this is a private test flight it's not live yet but message is is public already right it's also private oh it's also private yeah yeah because there is no way to test it until we have the test play of the app let me see
okay there it goes so this one is using the SDK of the group creates a new group with specific members maybe you can also assign the boot this vot is going to handle maybe gated access so you have everything you need and it goes into spam okay and it's like bet creative now how does it recognize that it's spam um you have a registry on a contract how it recognizes it's spam yeah an address uh it's reported as spam on a registry or yeah no this one by default is going to spam for now um then
the app needs to the app is going to check if this address is in your contacts you know that type of checking they we are not doing that right now but for example Converse V1 uh they are they they do check if you have uh previous they do check if the user is part of comers for example and if it's part of Converse then goes into the main inbox you know those are decisions that are up to every app uh at this point is no opinions is going to spam nice yeah that's it
