Group management

Managing group conversations is something really simple with Self SDK, let’s see an end to end example to understand how they work.

@groups = {} do |group|
    @groups[group.gid] = group
end do |msg|
    @groups[msg[:gid]].members << msg[:iss]
end do |msg|
end do |msg|
    return if msg.gid.nil?
    puts "[#{@groups[msg.gid].name}] #{msg.from}: #{msg.body}"
groups := make(map[string]*chat.Group, 0)
chat.ChatService().OnInvite(func(g *chat.Group) {
	groups[g.GID] = g
cs.OnLeave(func(iss, gid string) {
	delete(groups, gid)
chat.ChatService().OnJoin(func(iss, gid string) {
	if _, ok := groups[gid]; ok {
		groups[gid].Members = append(groups[gid].Members, iss)
chat.ChatService().OnMessage(func(cm *chat.Message) {
    if len(cm.GID) == 0 {
    fmt.Printf("[%s] %s: %s", groups[cm.GID].Name, cm.Iss, cm.Body) 
let groups = {} (g: ChatGroup) => {
  groups[g.gid] = g
  await groups[g.gid].message("hey!")
}) (iss: string, gid: string) => {
}) (iss: string, gid: string) => {
  delete groups[gid].members[iss]
}) (cm: ChatMessage) => {
    if (len(cm.gid) > 0) {
        console.log(`[${groups[cm.gid].name}] ${cm.iss}: ${cm.body}`)

As you can see this example manages every group incoming message, to keep an in memory updated list of groups with its members.

Creating a group

Your app is als also able to create a group by calling invite method.

members = [user1, user2, user3] "my_gid", "Group name", members
members = []string{user1, user2, user3}
client.ChatService().Invite("my_gid", "Group name", members)
let members = [user1, user2, user3]"my_gid", "Group name", members)

Have in mind you can send messages to a newly created group, but those messages will only be delivered to the group members that have decided to join the group.

Groups can also have an image as avatar, you can pass a file contents as parameter to chat invite to provide that image.

members = [user1, user2, user3]"") do |image|
    @groups[gid] =, "MagicGroup", members, { data:, mime: "image/jpg" })
members = []string{user1, user2, user3}
data, err := os.ReadFile("/tmp/dat")
client.ChatService().Invite("my_gid", "Group name", members, chat.InviteOptions{
    Data: data,
    Mime: "image.gif",
import * as fs from 'fs';
let data = fs.readFileSync('foo.txt','utf8');
let members = [user1, user2, user3]"my_gid", "Group name", members, {
    "data": data, 
    "mime": "image/gif",

Messaging and groups

Sending messages to a group is as easy as calling the message method on that group. Additionally once you receive a message on a group you will have access to all its helpers to continue the conversation without having to care about the group itself.