Messaging
Last updated
Last updated
If you need translation feature, see below.
Message translation feature is provided through Google Cloud Translation. To use this feature, register an appropriate Google Cloud Service Account Key on our dashboard.
Setting translationLanguage property in TPMessageRetrievalParams object with language code (ISO-639) retrieves message with its translated text.
Setting translationLanguage property in TPMessageSendParams with language code (ISO-639) when sending message will automatically translate the message text.
Supported languages (ISO-639) can be found .
Calling 'getTranslatedText' on TPMessage object will return a Key-Value map. Translated text(value) can be accessed from the map by using language code (used in 'translationLanguage' parameter) as key.
Messages are sorted by most recent (default).
Setting translationLanguage property in TPMessageRetrievalParams object will return TPMessage objects with translated texts via success block (success closure).
Use this to translate channel messages from the past.
For realtime message translation, see .
TPMessageRetrievalParams class is available starting from TalkPlus iOS SDK v0.5.3.
// get messages from channel
TPMessageRetrievalParams *params =
[[TPMessageRetrievalParams alloc] initWithChannel:channel];
params.lastMessage = lastMessage;
params.orderby = TPOrderByLatest;
params.translationLanguage = translationLanguage;
[[TalkPlus sharedInstance] getMessages:params
success:^(NSArray<TPMessage *> *tpMessages, BOOL hasNext) {
// SUCCESS
// If 'hasNext' is YES, call this method with the last object in 'tpMessages'.
} failure:^(int errorCode, NSError *error) {
// FAILURE
}];
// get a single message from channel
TPMessageRetrievalParams *params =
[[TPMessageRetrievalParams alloc] initWithChannel:channel];
params.messageId = messageId;
params.translationLanguage = translationLanguage;
[[TalkPlus sharedInstance] getMessage:tpChannel
messageId:messageId
translationLanguage:@""
success:^(TPMessage *tpMessage) {
} failure:^(int errorCode, NSError *error) {
}];
// get messages from the channel
let params = TPMessageRetrievalParams(channel: channel)
params?.lastMessage = message
params?.orderby = .orderByLatest
params?.translationLanguage = translationLanguage
TalkPlus.sharedInstance()?.getMessages(params, success: { tpMessages, hasNext in
// SUCCESS
// If 'hasNext' is true, call this method with the last object in 'tpMessages'.
}, failure: { (errorCode, error) in
// FAILURE
})
// get a single message from the channel
let params = TPMessageRetrievalParams(channel: channel)
params?.messageId = messageId
params?.translationLanguage = translationLanguage
TalkPlus.sharedInstance()?.getMessage(params, success: { tpMessage in
// SUCCESS
}, failure: { (errorCode, error) in
// FAILURE
})
View messages with file attachment.
Messages are sorted by most recent (default).
Setting translationLanguage property in TPMessageRetrievalParams object will return TPMessage objects with translated texts via success block (success closure).
Use this to translate channel messages from the past.
TPMessageRetrievalParams class is available starting from TalkPlus iOS SDK v0.5.3.
TPMessageRetrievalParams *params =
[[TPMessageRetrievalParams alloc] initWithChannel:channel];
params.lastMessage = lastMessage;
params.orderby = TPOrderByLatest;
params.translationLanguage = translationLanguage;
[[TalkPlus sharedInstance] getFileMessages:params
success:^(NSArray<TPMessage *> *tpMessages, BOOL hasNext) {
// SUCCESS
// If 'hasNext' is YES, call this method with the last object in 'tpMessages'.
} failure:^(int errorCode, NSError *error) {
// FAILURE
}];
let params = TPMessageRetrievalParams(channel: channel)
params?.lastMessage = message
params?.orderby = .orderByLatest
params?.translationLanguage = translationLanguage
TalkPlus.sharedInstance()?.getFileMessages(params,
success: { tpMessages, hasNext in
// SUCCESS
// If 'hasNext' is true, call this method with the last object in 'tpMessages'.
}, failure: { (errorCode, error) in
// FAILURE
})
The following message types are supported: text
, hidden
, custom
.
Push notification is not sent for hidden
message type.
admin
, admin_hidden
message type can only be sent from TalkPlus dashboard or by calling REST API.
If you have users you want to mention, you can pass an array of user IDs in the mentions field.
You can enter up to 10 key-value pairs in data field. The maximum size of key is 128 characters and the maximum size of value is 1024 characters. Both key and value must be strings.
Both message text
and data
cannot be empty when sending a message.
The maximum size of message text
is 8192 characters.
The maximum file upload size is 15MB.
Emojis supported by UTF-8 can be used in message text.
For custom emojis, required values can be put into message text then parsed directly.
TPMessageSendParams class is available starting from TalkPlus iOS SDK v0.5.3.
// send message
TPMessageSendParams * params =
[[TPMessageSendParams alloc] initWithContentType:TPMessageContentText
messageType:TPMessageText
channel:channel];
params.textMessage = text; // required
params.mentionUserIDs = mentionUserIDs;
params.parentMessageId = parentMessageId;
params.fileUrl = fileUrl;
params.translationLanguages = translationLanguages;
[[TalkPlus sharedInstance] sendMessage:params success:^(TPMessage *tpMessage) {
// SUCCESS
} failure:^(int errorCode, NSError *error) {
// FAILURE
}];
// file upload
TPMessageSendParams * params =
[[TPMessageSendParams alloc] initWithContentType:TPMessageContentFile
messageType:TPMessageText
channel:channel];
params.filePath = filePath; // required
params.textMessage = textMessage;
params.mentionUserIDs = mentionUserIDs;
params.parentMessageId = parentMessageId;
params.translationLanguages = translationLanguages;
[[TalkPlus sharedInstance] sendMessage:params success:^(TPMessage *tpMessage) {
// SUCCESS
} failure:^(int errorCode, NSError *error) {
// FAILURE
}];
// send message
let params = TPMessageSendParams(contentType: .text,
messageType: .text,
channel: channel)
params?.textMessage = textMessage
params?.mentionUserIDs = mentionUserIDs
params?.parentMessageId = parentMessageId
params?.translationLanguages = translationLanguages
params?.metaData = metaData
TalkPlus.sharedInstance()?.sendMessage(params) { tpMessage in
// SUCCESS
} failure: { (errorCode, error) in
// FAILURE
}
// file upload
let params = TPMessageSendParams(contentType: .file,
messageType: .text,
channel: channel)
params?.textMessage = textMessage
params?.filePath = filePath
params?.mentionUserIDs = mentionUserIDs
params?.parentMessageId = parentMessageId
params?.metaData = metaData
params?.translationLanguages = translationLanguages
TalkPlus.sharedInstance()?.sendMessage(params) { tpMessage in
// SUCCESS
} failure: { (errorCode, error) in
// FAILURE
}
View a single message.
// get a message from the channel
TPMessageRetrievalParams *params =
[[TPMessageRetrievalParams alloc] initWithChannel:channel];
params.translationLanguage = translationLanguage;
[[TalkPlus sharedInstance] getMessage:params
success:^(TPMessage *tpMessage) {
// SUCCESS
} failure:^(int errorCode, NSError *error) {
// FAILURE
}];
// get a message from the channel
let params = TPMessageRetrievalParams(channel: channel)
params?.translationLanguage = translationLanguage
TalkPlus.sharedInstance()?.getMessage(params, success: { tpMessage in
// SUCCESS
}, failure: { (errorCode, error) in
// FAILURE
})
Reply to another message.
TPMessageSendParams * params =
[[TPMessageSendParams alloc] initWithContentType:TPMessageContentText
messageType:TPMessageText
channel:channel];
params.textMessage = @"hello";
params.parentMessageId = @"anotherMessageIdThatIamReplyingTo";
[[TalkPlus sharedInstance] sendMessage:params success:^(TPMessage *tpMessage) {
// SUCCESS
} failure:^(int errorCode, NSError *error) {
// FAILURE
}];
let params = TPMessageSendParams(contentType: .text,
messageType: .text,
channel: channel)
params?.textMessage = "hello"
params?.parentMessageId = "anotherMessageIdThatIamReplyingTo"
TalkPlus.sharedInstance()?.sendMessage(params) { tpMessage in
// SUCCESS
} failure: { (errorCode, error) in
// FAILURE
}
You can mark a channel as read.
[[TalkPlus sharedInstance] markAsReadChannel:tpChannel
success:^(TPChannel *tpChannel) {
// SUCCESS
} failure:^(int errorCode, NSError *error) {
// FAILURE
}]
TalkPlus.sharedInstance()?.mark(asRead: tpChannel,
success: { tpChannel in
// SUCCESS
}, failure: { (errorCode, error) in
// FAILURE
})
You can add/remove reaction to a message.
reaction
must be alphanumeric and between 1 and 64 characters long.
Each message can have up to 10 reaction
types.
Each reaction
type can contain up to 100 user IDs.
// add reaction
[[TalkPlus sharedInstance] addMessageReaction:tpMessage
reaction:reaction
success:^(TPMessage *tpMessage) {
// SUCCESS
} failure:^(int errorCode, NSError *error) {
// FAILURE
}];
// remove reaction
[[TalkPlus sharedInstance] removeMessageReaction:tpMessage
reaction:reaction
success:^(TPMessage *tpMessage) {
// SUCCESS
} failure:^(int errorCode, NSError *error) {
// FAILURE
}];
// see reactions in message object
[tpMessage getReactions];
/*
{
"happy": [
"user1",
"user2"
],
"sad": [
"user3"
]
}
*/
// add reaction
TalkPlus.sharedInstance()?.addMessageReaction(tpMessage,
reaction: reaction,
success: { tpMessage in
// SUCCESS
}, failure: { (errorCode, error) in
// FAILURE
})
// remove reaction
TalkPlus.sharedInstance()?.removeMessageReaction(tpMessage,
reaction: reaction,
success: { tpMessage in
// SUCCESS
}, failure: { (errorCode, error) in
// FAILURE
})
// see reactions in message object
tpMessage.getReactions()
/*
{
"happy": [
"user1",
"user2"
],
"sad": [
"user3"
]
}
*/
You can find out how many channel members have not read a particular message.
[tpChannel getMessageUnreadCount:tpMessage];
tpChannel.getMessageUnreadCount(tpMessage)
You can delete your own message.
[[TalkPlus sharedInstance] deleteMessage:tpChannel
message:tpMessage
success:^{
// SUCCESS
} failure:^(int errorCode, NSError *error) {
// FAILURE
}];
TalkPlus.sharedInstance()?.deleteMessage(tpChannel,
message: tpMessage,
success: {
// SUCCESS
}, failure: { (errorCode, error) in
// FAILURE
})
For realtime message translation, see .
If you need to handle files bigger than 15MB, see .
Setting translationLanguages property in TPMessageSendParams object will return TPMessage objects with translated texts via ''success block (success closure). Message recipient will be able to check the message via "messageReceived" event.