Skip to content

Instantly share code, notes, and snippets.

@daqo
Last active January 16, 2018 19:06
Show Gist options
  • Save daqo/24b10840dc9e7ac40091b7397e2a9be5 to your computer and use it in GitHub Desktop.
Save daqo/24b10840dc9e7ac40091b7397e2a9be5 to your computer and use it in GitHub Desktop.

Discoverable Group Channels (Backend Work):

Custom Attributes

  • Each discoverable group channel will carry the following custom attributes:
topic: string
org_uuid: string
description: string
locked: string
imageUrl: string
groupChat: bool
discoverableGroup: bool

Rules

  • For unlocked group chats, mobile clients can add themselves as a member to the channel when 'Join Group' is pressed.
  • For unlocked group chats, mobile clients can remove themselves as a member from the channel when 'Leave Group' is pressed.
  • If channel members limit is reached, the mobile client must throw a client-side "max limit reached" error when joining. Maximum member count for a group is 250.
  • Mobile client shouldn't change custom_attributes on a channel.
  • Mobile client shouldn't delete a channel.

APIs

  1. To get a list of all discoverable channels in a organization, run the following query (cherry pick whatever field you are interested in). Note that you are only able to call discoverableGroupChats on organizations the current user is accepted into.
{
  organization(uuid: "34f6ffef-ffaa-4964-8112-14580071bff5") {
    discoverableGroupChats {
      edges {
        node {
          organization {
            name
          }
          sid
          imageUrl
          channelType
          dateCreated
          dateUpdated
          customAttributes
          membersCount
          locked
          topic
          description
          pendingRequestToJoin
          sampleMembers {
            edges {
              node {
                name
                profilePhoto {
                  url(size: 40)
                }
              }
            }
          }
        }
      }
    }
  }
}

locked tells you whether the channel is locked or not. pendingRequestToJoin returns true in case there is an existing req-to-join-channel entry for current user for that channel.

  1. To get the list of joined channels for the current user pass an array of channel SIDs to joinedGroupChannels field: (joined group channels returns an array of TwilioDiscoverableGroupChannel objects). joinedGroupChannels can only be called for the currently logged in user.
{
  me {
    joinedGroupChannels(sids: ["CH8011bb5a82d64b9ab6a11c4527fd0c52"]) {
      sid
      topic
      ...
    }
  }
}
  1. If the channel is locked, the client needs to call createNotificationRequestToJoinGroupChat mutation to request to join that channel. Simply pass channelSID as an input to mutation. Example:
mutation {
  createNotificationRequestToJoinGroupChat(input: {
      clientMutationId: "aaa", 
      channelSID: "CH6a4623aafe62499785627f52f2564ac2"
  }) {
    me {
      name
    }
  }
}
  1. To cancel an already issued request-to-join-channel entry, call destroyNotificationRequestToJoinGroupChat mutation and pass a channelSID. Example:
mutation {
  destroyNotificationRequestToJoinGroupChat(input: {
    clientMutationId: "aaa", 
    channelSID: "CH6a4623aafe62499785627f52f2564ac2"
  }) {
    me {
      name
    }
  }
}

Upon receiving this mutation, backend will look for an existing channel-join-request for that (logged-in-user, channelSID) pair.

Both createNotificationRequestToJoinGroupChat and destroyNotificationRequestToJoinGroupChat mutations return the current user as a response payload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment