Conversation
Create conversation:
CMPRoleAttributes *ownerAttributes = [[CMPRoleAttributes alloc] initWithCanSend:YES canAddParticipants:YES canRemoveParticipants:YES];
CMPRoleAttributes *participantAttributes = [[CMPRoleAttributes alloc] initWithCanSend:YES canAddParticipants:NO canRemoveParticipants:NO];
CMPRoles *roles = [[CMPRoles alloc] initWithOwnerAttributes:ownerAttributes participantAttributes:participantAttributes];
CMPConversationParticipant *owner = [[CMPConversationParticipant alloc] initWithID:profileID role:@"owner"];
CMPNewConversation *newConversation = [[CMPNewConversation alloc] initWithID:@"{id}" name:@"{name}" description:@"{description}" roles:roles participants:@[owner] isPublic:@(NO)];
[client.services.messaging addConversationWithConversation:weakSelf.conversation completion:^(CMPResult<CMPConversation *> *result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
let participant = ConversationParticipant(id: "{participantId}", role: .participant)
let ownerAttributes = RoleAttributes(canSend: true, canAddParticipants: true, canRemoveParticipants: true)
let participantAttributes = RoleAttributes(canSend: true, canAddParticipants: false, canRemoveParticipants: false)
let roles = Roles(ownerAttributes: ownerAttributes, participantAttributes: participantAttributes)
let newConversation = NewConversation(id: "{id}", name: "{name}", description: "{description}", roles: roles, participants: [participant], isPublic: NSNumber.init(booleanLiteral: false))
client.services.messaging.addConversation(conversation: newConversation) { (result) in
if let err = result.error {
// error
} else if let obj = result.object {
// success
}
}
Query all conversations:
[_client.services.messaging getConversationsWithProfileID:_client.profileID isPublic:YES completion:^(CMPResult<NSArray<CMPConversation *> *> * _Nonnull) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.messaging.getConversations(profileID: client.profileID!, isPublic: true) { (result) in
if let err = result.error {
// error
} else if let obj = result.object?.compactMap({ $0 as? Profile }) {
// success
}
}
Query specific conversation:
[client.services.messaging getConversationWithConversationID:@"{id}" completion:^(CMPResult<CMPConversation *> *result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.messaging.getConversation(conversationID: "{id}") { (result) in
if let err = result.error {
// error
} else if let obj = result.object {
// success
}
}
Update conversation:
CMPConversationUpdate *update = [[CMPConversationUpdate alloc] initWithID:@"{id}" name:@"{name}" description:@"{description}" roles:roles isPublic:@(NO)];
[client.services.messaging updateConversationWithConversationID:@"{id}" conversation:update eTag:nil completion:^(CMPResult<CMPConversation *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
let ownerAttributes = RoleAttributes(canSend: true, canAddParticipants: true, canRemoveParticipants: true)
let participantAttributes = RoleAttributes(canSend: true, canAddParticipants: false, canRemoveParticipants: false)
let roles = Roles(ownerAttributes: ownerAttributes, participantAttributes: participantAttributes)
let update = ConversationUpdate(id: "{id}", name: "{name}", description: "{description}", roles: roles, isPublic: NSNumber.init(booleanLiteral: false))
client.services.messaging.updateConversation(conversationID: "{id}", conversation: update, eTag: nil) { (result) in
if let err = result.error {
// error
} else if let obj = result.object {
// success
}
}
Delete conversation:
[client.services.messaging deleteConversationWithConversationID:@"{id}" eTag:nil completion:^(CMPResult<NSNumber *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.messaging.deleteConversation(conversationID: "{id}", eTag: nil) { (result) in
if let err = result.error {
// error
} else if let obj = result.object?.boolValue, obj == true {
// success
}
}
Participants
Get participants:
[client.services.messaging getParticipantsWithConversationID:@"{id}" completion:^(CMPResult<NSArray<CMPConversationParticipant *> *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.messaging.getParticipants(conversationID: "{id}") { (result) in
if let err = result.error {
// error
} else if let obj = result.object?.compactMap({ $0 as ConversationParticipant }) {
// success
}
}
Add participants:
NSArray<CMPConversationParticipant *> *participants = @[[[CMPConversationParticipant alloc] initWithID:@"@{id1}" role:@"{role}"], [[CMPConversationParticipant alloc] initWithID:@"@{id2}" role:@"{role}"]];
[client.services.messaging addParticipantsWithConversationID:@"{id}" participants:participants completion:^(CMPResult<NSNumber *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
let participant = ConversationParticipant(id: "{participantId}", role: .participant)
client.services.messaging.addParticipants(conversationID: "{id}", participants: []) { (result) in
if let err = result.error {
// error
} else if let obj = result.object?.boolValue, obj == true {
// success
}
}
Remove participants:
[client.services.messaging removeParticipantsWithConversationID:@"{id}" participants:participants completion:^(CMPResult<NSNumber *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
let participant = ConversationParticipant(id: "{participantId}", role: .participant)
client.services.messaging.removeParticipants(conversationID: "{id}", participants: [participant]) { (result) in
if let err = result.error {
// error
} else if let obj = result.object?.boolValue, obj == true {
// success
}
}
Messages
Query messages:
[client.services.messaging getMessagesWithConversationID:@"{id}" limit:100 from:0 completion:^(CMPResult<CMPGetMessagesResult *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.messaging.getMessages(conversationID: "{id}") { (result) in
if let err = result.error {
// error
} else if let obj = result.object {
// success
}
}
Create message:
CMPMessagePart *part = [[CMPMessagePart alloc] initWithName:@"{name}" type:@"{type}" url:nil data:@"{data}" size:@(123)];
CMPMessageAlert *alert = [[CMPMessageAlert alloc] initWithPlatforms:[[CMPMessageAlertPlatforms alloc] initWithApns:@{} fcm:@{}]];
CMPSendableMessage *message = [[CMPSendableMessage alloc] initWithMetadata:@{} parts:@[part] alert:alert];
[client.services.messaging sendMessage:message toConversationWithID:@"{id}" completion:^(CMPResult<CMPSendMessagesResult *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
let text = "some message"
let part = MessagePart(name: "part1", type: "plain/text", url: nil, data: text, size: NSNumber(integerLiteral: text.count))
let msg = SendableMessage(metadata: ["custom field" : "custom value"], parts: [part], alert: nil)
client.services.messaging.send(message: msg, conversationID: "{id}") { (result) in
if let err = result.error {
// error
} else if let obj = result.object {
// success
}
}
Update messages status':
[client.services.messaging updateStatusForMessagesWithIDs:@[@"{id1}", @"{id2}"] status:@"read" conversationID:@"{id}" timestamp:[NSDate date] completion:^(CMPResult<NSNumber *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.messaging.updateStatus(messageIDs: ["{id1}", "{id2}"], status: .delivered, conversationID: "{id}", timestamp: Date()) { (result) in
if let err = result.error {
// error
} else if let obj = result.object?.boolValue, obj == true {
// success
}
}
Events
Query events:
[client.services.messaging queryEventsWithConversationID:@"{id}" limit:0 from:100 completion:^(CMPResult<NSArray<CMPEvent *> *> * result) {
if (result.error) {
// error occurred
} else {
// success
}
}];
client.services.messaging.queryEvents(conversationID: "{id}") { (result) in
if let err = result.error {
// error
} else if let obj = result.object?.compactMap({ $0 as? Event }) {
// success
}
}