Message Types
In many use cases, you define descriptive, predefined categories of messages. This helps your app grow without being limited by basic messaging structures. You can also apply conditional processing to messages of the same type, for example:
- Text messaging.
- Text messaging with language translations embedded in the message.
- Hosted image/file messages, where the file is static and the URL is referenced.
- Video files that contain thumbnails and loading icons.
- Polling and questionnaire messages where you also supply predefined answers.
- Invitations to new channels for private or group chat.
- Action messages for the app to do something for this user.
- Session data linked to a third-party such as video service or streaming event.
Custom vs. internal message type
A message can include two type fields:
- Integer
messageType
refers to the internal PubNub type of the message. - String
custom_message_type
refers to a business-specific label or category to messages, signals, and files.
Server response
Every message sent through PubNub has its internal integer message type returned as type
in the subscribe payload. On the contrary, a custom message type string (returned as cmt
) is only returned when it has been explicitly set beforehand. The cmt
value in the returned server response is the same as the value of custom_message_type
(name may vary across SDKs) used during a publish.
Internal message type | Description |
---|---|
0 | Regular message |
2 | App Context event |
3 | Message Actions event |
4 | File message |
When working with historical messages, you can choose to return the type and the custom message type in the response by enabling the include_custom_message_type
flag (name varies across SDKs). For more information on fetching historical messages and how those parameters are returned, refer to Retrieve messages.
Custom message type not present in payload
If you don't set the custom_message_type
parameter during a publish, it is not present in the subscribe or history payloads.
Descriptive message types
Consider these three messages:
{payload: “Hello I am a Message"}
{payload: "https://cdn.app/your/image/here.png"}
{payload: "https://cdn.app/your/video/here.mp4"}
Because of the way these messages are constructed, you may run into a number of problems while trying to interpret their payloads in your app. Should you just scan for text? Should you check if every message starts with https
? Should you look for .fileType
at the end of each message?
You can make your app easier to expand upon by including message types in the publish call. Making types more descriptive also makes it easier to interpret these messages later on.
Generic payload | Descriptive payload |
---|---|
{payload: “Hello, I am a message"} | {message:"Hello, I am a Message"} with custom_message_type set to text |
{payload: "https://cdn.app/your/image/here.png"} | {full:"https://cdn.app/your/image/here.png", thumbnail:" https://cdn.app/your/image/here_thumbnail.png"} with custom_message_type set to image |
{payload: "https://cdn.app/your/video/here.mp4"} | {url:"https://cdn.app/your/video/here.mp4", thumbnail:"https://cdn.app/your/video/here_thumbnail.png"} with custom_message_type set to video |
When your app receives these kinds of messages, it can process them differently displaying text, images and videos according to their respective types.
Future-proof message types
You can add fail-safe measures into your app. If you introduce new message types, older versions of your app can prompt users to upgrade to unlock the features the new message types provide.
Check out these examples of publishing a Hello World! message with the custom_message_type
parameter set to text-message
:
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1pubnub.publish()
2 .message("Hello World!")
3 .channel("my_channel")
4 .customMessageType("text-message")
5 .async(new PNCallback<PNPublishResult>() {
6 @Override
7 public void onResponse(PNPublishResult result, PNStatus status) {
8 if(!status.isError()) {
9 System.out.println("pub timetoken: " + result.getTimetoken());
10 }
11 System.out.println("pub status code: " + status.getStatusCode());
12 }
13 });
1pubnub.publish(
2 {
3 channel: "my_channel",
4 message: {"Hello World!"},
5 custom_message_type: "text-message"
6 },
7 function(status, response) {
8 console.log(status);
9 console.log(response);
10 }
11);
1pubnub.publish(
2 message="Hello World!",
3 channel = "my_channel",
4 custom_message_type = "text-message"
5).async { result, status ->
6 if (!status.error) {
7 println("Publish timetoken ${result!!.timetoken}")
8 }
9 println("Status code ${status.statusCode}")
10}
1self.client.publish()
2 .message(@"Hello World!")
3 .channel(@"my_channel")
4 .customMessageType(@"text-message")
5 .performWithCompletion(^(PNPublishStatus *status) {
6 if (!status.isError) {
7 } else {
8 }
9});
1$result = $pubnub->publish()
2 ->channel("my_channel")
3 ->message("Hello World!")
4 ->customMessageType("text-message")
5 ->meta(["name" => "Alex"])
6 ->sync();
1def publish_callback(result, status):
2 if status.isError:
3 print status.statusCode
4 elif
5 print result.timetoken
6
7pubnub.publish()\
8 .channel("my_channel")\
9 .message({"Hello World!"})\
10 .custom_message_type("text-message")\
11 .pn_async(publish_callback)
1pubnub.publish(
2 channel: "my_channel",
3 message: ["Hello World!"],
4 customMessageType: "text-message"
5){ result in
6 switch result {
7 case let .success(response):
8 print("succeeded: \(response)")
9
10 case let .failure(error):
11 print("failed: \(error.localizedDescription)")
12 }
13}
Custom message type
Like we showed before, the optional string parameter custom_message_type
(name may vary across SDKs) in the Publish and Files APIs allows you to add business-specific label or category to messages, signals, and files.
You can use this parameter to easily filter, group or apply conditional logic based on the value of the custom_message_type
parameter. Refer to Publish with type in payload and Publish with type in metadata for more information on filtering by custom message type.
Refer to Sending Messages, Sending Signals, and Sending Files for more information on messages.
The value or the custom_message_type
parameter must be a case-sensitive, alphanumeric string from 3 to 50 characters (dashes and underscores are allowed). The value can't start with special characters or the pn_
or pn-
string.
SDKs supporting custom_message_type
For more info on custom_message_type
, go to the following SDKs that already support this parameter: Objective-C, Swift, Java, JavaScript, Python, PHP, and Kotlin.
Recommendations
Message payloads and their types should be easy to read and extendable. As your app grows, you want to ensure that future releases don't break old versions.
Below is a list of payload structures and message types that might be helpful to you:
Text
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1pubnub.publish()
2 .message(new JSONObject()
3 .put("content", new JSONObject()
4 .put("message", "This is a message"))
5 .put("sender", "Mathew.Jenkinson"))
6 .channel("my_channel")
7 .customMessageType("text-message")
8 .async(new PNCallback<PNPublishResult>() {
9 @Override
10 public void onResponse(PNPublishResult result, PNStatus status) {
11 if(!status.isError()) {
12 System.out.println("pub timetoken: " + result.getTimetoken());
13 }
14 System.out.println("pub status code: " + status.getStatusCode());
15 }
show all 16 lines1pubnub.publish(
2 {
3 channel: "my_channel",
4 message: {
5 "content": {
6 "message": "This is a message"
7 },
8 "sender": "Mathew.Jenkinson"
9 },
10 customMessageType: "text-message"
11 },
12 function(status, response) {
13 console.log(status);
14 console.log(response);
15 }
show all 16 lines1pubnub.publish(
2 mapOf("content" to mapOf(
3 "message" to "This is message"),
4 "sender" to "Mathew.Jenkinson")),
5 channel = "my_channel",
6 custom_message_type = "text-message"
7).async { result, status ->
8 if (!status.error) {
9 println("Publish timetoken ${result!!.timetoken}")
10 }
11 println("Status code ${status.statusCode}")
12}
1self.client.publish()
2 .message(@{
3 @"content": @{
4 @"message": @"This is a message"
5 },
6 @"sender": @"Mathew.Jenkinson"
7 })
8 .channel(@"my_channel")
9 .customMessageType(@"text-message")
10 .performWithCompletion(^(PNPublishStatus *status) {
11 if (!status.isError) {
12 } else {
13 }
14});
1$result = $pubnub->publish()
2 ->channel("my_channel")
3 ->message([
4 "content" => [
5 "message" => "This is a message"
6 ],
7 "sender" => "Mathew.Jenkinson"
8 ])
9 ->customMessageType("text-message")
10 ->meta(["name" => "Alex"])
11 ->sync();
1def publish_callback(result, status):
2 if status.isError:
3 print status.statusCode
4 elif
5 print result.timetoken
6
7pubnub.publish()\
8 .channel("my_channel")\
9 .message({
10 "content": {
11 "message": "This is a message"
12 },
13 "sender": "Mathew.Jenkinson"
14 })\
15 .custom_message_type("text-message")\
show all 16 lines1pubnub.publish(
2 channel: "my_channel",
3 message: [
4 "content": [
5 "message": "This is a message"
6 ],
7 "sender": "Mathew.Jenkinson"
8 ] as [String: AnyJSON],
9 customMessageType: "text-message"
10) { result in
11 switch result {
12 case let .success(response):
13 print("succeeded: \(response)")
14 case let .failure(error):
15 print("failed: \(error.localizedDescription)")
show all 17 linesMulti-language text
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1JSONObject data = new JSONObject()
2 .put("content", new JSONObject()
3 .put("message", new JSONObject()
4 .put("en", "This is a message")
5 .put("es", "Este es un mensaje")
6 .put("de", "Dies ist eine Nachricht")
7 .put("nl", "Dit is een bericht")))
8 .put("sender", "Mathew.Jenkinson");
9
10pubnub.publish()
11 .message(data)
12 .channel("my_channel")
13 .customMessageType("multi-language-text")
14 .async(new PNCallback<PNPublishResult>() {
15 @Override
show all 22 lines1pubnub.publish(
2 {
3 channel: "my_channel",
4 message: {
5 "content": {
6 "message": {
7 "en": "This is a message",
8 "es": "Este es un mensaje",
9 "de": "Dies ist eine Nachricht",
10 "nl": "Dit is een bericht"
11 }
12 },
13 "sender": "Mathew.Jenkinson"
14 },
15 customMessageType: "multi-language-text"
show all 23 lines1val data = mapOf(
2 "content" to mapOf(
3 "message" to mapOf(
4 "en" to "This is a message",
5 "es" to "Este es un mensaje",
6 "de" to "Dies ist eine Nachricht",
7 "nl" to "Dit is een bericht"
8 )
9 ), "sender" to "Mathew.Jenkinson"
10 )
11
12pubnub.publish()
13 .message(data)
14 .channel("my_channel")
15 .customMessageType("multi-language-text")
show all 22 lines1self.client.publish()
2 .message(@{
3 @"content": @{
4 @"message": @{
5 @"en": @"This is a message",
6 @"es": @"Este es un mensaje",
7 @"de": @"Dies ist eine Nachricht",
8 @"nl": @"Dit is een bericht"
9 }
10 },
11 @"sender": @"Mathew.Jenkinson"
12 })
13 .channel(@"my_channel")
14 .customMessageType(@"multi-language-text")
15 .performWithCompletion(^(PNPublishStatus *status) {
show all 19 lines1$result = $pubnub->publish()
2 ->channel("my_channel")
3 ->message([
4 "content" => [
5 "message" => [
6 "en" => "This is a message",
7 "es" => "Este es un mensaje",
8 "de" => "Dies ist eine Nachricht",
9 "nl" => "Dit is een bericht"
10 ]
11 ],
12 "sender" => "Mathew.Jenkinson"
13 ])
14 ->customMessageType("multi-language-text")
15 ->meta(["name" => "Alex"])
show all 16 lines1def publish_callback(result, status):
2 if status.is_error():
3 print("Status code: {}".format(status.error_data.information))
4 else:
5 print("Publish timetoken: {}".format(result.timetoken))
6
7pubnub.publish() \
8 .channel("my_channel") \
9 .message({
10 "content": {
11 "message": {
12 "en": "This is a message",
13 "es": "Este es un mensaje",
14 "de": "Dies ist eine Nachricht",
15 "nl": "Dit is een bericht"
show all 21 lines1pubnub.publish(
2 channel: "my_channel",
3 message: [
4 "content": [
5 "message": [
6 "en": "This is a message",
7 "es": "Este es un mensaje",
8 "de": "Dies ist eine Nachricht",
9 "nl": "Dit is een bericht"
10 ]
11 ],
12 "sender": "Mathew.Jenkinson"
13 ] as [String: AnyJSON],
14 customMessageType: "multi-language-text"
15) { result in
show all 22 linesText with image
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1pubnub.publish()
2 .message(new JSONObject()
3 .put("content", new JSONObject()
4 .put("text", "The weather is gorgeous today. Who's available to meet up for lunch at Bob’s Diner? 🌞")
5 .put("attachments", new JSONArray()
6 .put(new JSONObject()
7 .put("image", new JSONObject()
8 .put("source", "https://www.pubnub.com/pubnub_logo.svg")
9 )
10 )
11 )
12 .put("sender", "Mathew.Jenkinson"))
13 .channel("my_channel")
14 .customMessageType("text-with-image")
15 .async(new PNCallback<PNPublishResult>() {
show all 23 lines1pubnub.publish(
2 {
3 channel: "my_channel",
4 message: {
5 "content": {
6 "text": "The weather is gorgeous today. Who's available to meet up for lunch at Bob’s Diner? 🌞",
7 "attachments": [
8 {
9 "image": {
10 "source": "https://www.pubnub.com/pubnub_logo.svg"
11 }
12 }
13 ],
14 "sender": "Mathew.Jenkinson"
15 }
show all 23 lines1pubnub.publish(
2 channel: "my_channel",
3 message: mapOf(
4 "content" to mapOf(
5 "text" to "The weather is gorgeous today. Who's available to meet up for lunch at Bob's Diner? 🌞",
6 "attachments" to listOf(
7 mapOf(
8 "image" to mapOf(
9 "source" to "https://www.pubnub.com/pubnub_logo.svg"
10 )
11 )
12 ),
13 "sender" to "Mathew.Jenkinson"
14 )
15 ),
show all 25 lines1self.client.publish()
2 .message(@{
3 @"content": @{
4 @"text": @"The weather is gorgeous today. Who's available to meet up for lunch at Bob’s Diner? 🌞",
5 @"attachments": @[
6 @{
7 @"image": @{
8 @"source": @"https://www.pubnub.com/pubnub_logo.svg"
9 }
10 }
11 ],
12 @"sender": @"Mathew.Jenkinson"
13 }
14 })
15 .channel(@"my_channel")
show all 21 lines1$result = $pubnub->publish()
2 ->channel("my_channel")
3 ->message([
4 "content" => [
5 "text" => "The weather is gorgeous today. Who's available to meet up for lunch at Bob’s Diner? 🌞",
6 "attachments" => [
7 [
8 "image" => [
9 "source" => "https://www.pubnub.com/pubnub_logo.svg"
10 ]
11 ]
12 ],
13 "sender" => "Mathew.Jenkinson"
14 ]
15 ])
show all 18 lines1def publish_callback(result, status):
2 if status.isError:
3 print status.statusCode
4 else:
5 print result.timetoken
6
7pubnub.publish()\
8 .channel("my_channel")\
9 .message({
10 "content": {
11 "text": "The weather is gorgeous today. Who's available to meet up for lunch at Bob’s Diner? 🌞",
12 "attachments": [
13 {
14 "image": {
15 "source": "https://www.pubnub.com/pubnub_logo.svg"
show all 23 lines1struct TextWithImage: JSONCodable {
2 let text: String
3 let attachments: [[String: AnyJSON]]
4 let sender: String
5}
6
7pubnub.publish(
8 channel: "my_channel",
9 message: TextWithImage(
10 text: "The weather is gorgeous today. Who's available to meet up for lunch at Bob's Diner? 🌞",
11 attachments: [
12 [
13 "image": [
14 "source": "https://www.pubnub.com/pubnub_logo.svg"
15 ]
show all 28 linesDocument
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1pubnub.publish()
2 .message(new JSONObject()
3 .put("content", new JSONObject()
4 .put("link", "https://my/full/document.pdf")
5 .put("thumbnail", "https://my/thumbnail/image.png"))
6 .put("sender", "Mathew.Jenkinson"))
7 .channel("my_channel")
8 .customMessageType("document")
9 .async(new PNCallback<PNPublishResult>() {
10 @Override
11 public void onResponse(PNPublishResult result, PNStatus status) {
12 if(!status.isError()) {
13 System.out.println("pub timetoken: " + result.getTimetoken());
14 }
15 System.out.println("pub status code: " + status.getStatusCode());
show all 17 lines1pubnub.publish(
2 {
3 channel: "my_channel",
4 message: {
5 "content": {
6 "link": "https://my/full/document.pdf",
7 "thumbnail": "https://my/thumbnail/image.png"
8 },
9 "sender": "Mathew.Jenkinson"
10 },
11 customMessageType: "document"
12 },
13 function(status, response) {
14 console.log(status);
15 console.log(response);
show all 17 lines1pubnub.publish(
2 message = mapOf(
3 "content" to mapOf(
4 "link" to "https://my/full/document.pdf",
5 "thumbnail" to "https://my/thumbnail/image.png"
6 ),
7 "sender" to "Mathew.Jenkinson"
8 ),
9 channel = "my_channel",
10 customMessageType = "document"
11).async { result, status ->
12 if (!status.error) {
13 println("Publish timetoken ${result!!.timetoken}")
14 }
15 println("Status code ${status.statusCode}")
show all 16 lines1self.client.publish()
2 .message(@{
3 @"content": @{
4 @"content": @{
5 @"link": @"https://my/full/document.pdf",
6 @"thumbnail": @"https://my/thumbnail/image.png"
7 },
8 @"sender": @"Mathew.Jenkinson"
9 },
10 })
11 .channel(@"my_channel")
12 .customMessageType(@"document")
13 .performWithCompletion(^(PNPublishStatus *status) {
14 if (!status.isError) {
15 NSLog(@"Publish timetoken %@", status.data.timetoken);
show all 19 lines1$result = $pubnub->publish()
2 ->channel("my_channel")
3 ->message([
4 "content" => [
5 "link" => "https://my/full/document.pdf",
6 "thumbnail" => "https://my/thumbnail/image.png"
7 ],
8 "sender" => "Mathew.Jenkinson"
9 ])
10 ->customMessageType("document")
11 ->meta(["name" => "Alex"])
12 ->sync();
1def publish_callback(result, status):
2 if status.isError:
3 print(status.statusCode)
4 else:
5 print(result.timetoken)
6
7pubnub.publish()\
8 .channel("my_channel")\
9 .message({
10 "content": {
11 "content": {
12 "link": "https://my/full/document.pdf",
13 "thumbnail": "https://my/thumbnail/image.png"
14 },
15 "sender": "Mathew.Jenkinson"
show all 19 lines1pubnub.publish(
2 channel: "my_channel",
3 message: [
4 "content": [
5 "content": [
6 "link": "https://my/full/document.pdf",
7 "thumbnail": "https://my/thumbnail/image.png"
8 ],
9 "sender": "Mathew.Jenkinson"
10 ]
11 ] as [String: AnyJSON],
12 customMessageType: "document"
13) { result in
14 switch result {
15 case let .success(response):
show all 20 linesVideo
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1pubnub.publish()
2 .message(new JSONObject()
3 .put("content", new JSONObject()
4 .put("url", "https://my/video/file.png")
5 .put("thumbnail", "https://my/video/image.png"))
6 .put("sender", "Mathew.Jenkinson"))
7 .channel("my_channel")
8 .customMessageType("video")
9 .async(new PNCallback<PNPublishResult>() {
10 @Override
11 public void onResponse(PNPublishResult result, PNStatus status) {
12 if(!status.isError()) {
13 System.out.println("pub timetoken: " + result.getTimetoken());
14 }
15 System.out.println("pub status code: " + status.getStatusCode());
show all 17 lines1pubnub.publish(
2 {
3 channel: "my_channel",
4 message: {
5 "content": {
6 "url": "https://my/video/file.png",
7 "thumbnail": "https://my/video/image.png"
8 },
9 "sender": "Mathew.Jenkinson"
10 },
11 customMessageType: "video"
12 },
13 function(status, response) {
14 console.log(status);
15 console.log(response);
show all 17 lines1pubnub.publish(
2 message = mapOf(
3 "content" to mapOf(
4 "content" to mapOf(
5 "url" to "https://my/video/file.png",
6 "thumbnail" to "https://my/video/image.png"
7 )
8 ),
9 "sender" to "Mathew.Jenkinson"
10 ),
11 channel = "my_channel",
12 customMessageType = "video"
13).async { result, status ->
14 if (!status.error) {
15 println("Publish timetoken ${result!!.timetoken}")
show all 18 lines1self.client.publish()
2 .message(@{
3 @"content": @{
4 @"content": @{
5 @"url": @"https://my/video/file.png",
6 @"thumbnail": @"https://my/video/image.png"
7 },
8 @"sender": @"Mathew.Jenkinson"
9 }
10 })
11 .channel(@"my_channel")
12 .customMessageType(@"video")
13 .performWithCompletion(^(PNPublishStatus *status) {
14 if (!status.isError) {
15 } else {
show all 17 lines1$result = $pubnub->publish()
2 ->channel("my_channel")
3 ->message([
4 "content" => [
5 "url" => "https://my/video/file.png",
6 "thumbnail" => "https://my/video/image.png"
7 ],
8 "sender" => "Mathew.Jenkinson"
9 ])
10 ->customMessageType("video")
11 ->meta(["name" => "Alex"])
12 ->sync();
1def publish_callback(result, status):
2 if status.isError:
3 print status.statusCode
4 elif
5 print result.timetoken
6
7pubnub.publish()\
8 .channel("my_channel")\
9 .message({
10 "content": {
11 "url": "https://my/video/file.png",
12 "thumbnail": "https://my/video/image.png"
13 },
14 "sender": "Mathew.Jenkinson"
15 })\
show all 17 lines1pubnub.publish(
2 channel: "my_channel",
3 message: [
4 "content": [
5 "url": "https://my/video/file.png",
6 "thumbnail": "https://my/video/image.png"
7 ],
8 "sender": "Mathew.Jenkinson"
9 ] as [String: AnyJSON],
10 customMessageType: "video"
11) { result in
12 switch result {
13 case let .success(response):
14 print("succeeded: \(response)")
15 case let .failure(error):
show all 18 linesTyping indicator
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1pubnub.signal()
2 .message(new JSONObject()
3 .put("content", new JSONObject()
4 .put("event", "typing"))
5 .put("sender", "Mathew.Jenkinson"))
6 .channel("my_channel")
7 .customMessageType("typing-indicator")
8 .async(new PNCallback<PNPublishResult>() {
9 @Override
10 public void onResponse(PNPublishResult result, PNStatus status) {
11 if(!status.isError()) {
12 System.out.println("pub timetoken: " + result.getTimetoken());
13 }
14 System.out.println("pub status code: " + status.getStatusCode());
15 }
show all 16 lines1pubnub.signal(
2 {
3 channel: "my_channel",
4 message: {
5 "content": {
6 "event": "typing"
7 },
8 "sender": "Mathew.Jenkinson"
9 },
10 customMessageType: "typing-indicator"
11 },
12 function(status, response) {
13 console.log(status);
14 console.log(response);
15 }
show all 16 lines1pubnub.signal(
2 message = mapOf(
3 "content" to mapOf(
4 "message" to mapOf(
5 "content" to mapOf(
6 "event" to "typing"
7 )
8 ),
9 "sender" to "Mathew.Jenkinson"
10 )
11 ),
12 channel = "my_channel",
13 customMessageType = "typing-indicator"
14).async { result, status ->
15 if (!status.error) {
show all 19 lines1self.client.signal()
2 .message(@{
3 @"content": @{
4 @"message": @{
5 @"content": @{
6 @"event": @"typing"
7 },
8 @"sender": @"Mathew.Jenkinson"
9 }
10 }
11 })
12 .channel(@"my_channel")
13 .customMessageType(@"typing-indicator")
14 .performWithCompletion(^(PNPublishStatus *status) {
15 if (!status.isError) {
show all 18 lines1$result = $pubnub->signal()
2 ->channel("my_channel")
3 ->message([
4 "content" => [
5 "content" => [
6 "event" => "typing"
7 ],
8 "sender" => "Mathew.Jenkinson"
9 ]
10 ])
11 ->customMessageType("typing-indicator")
12 ->meta(["name" => "Alex"])
13 ->sync();
1def publish_callback(result, status):
2 if status.isError:
3 print status.statusCode
4 else:
5 print result.timetoken
6
7pubnub.signal()\
8 .channel("my_channel")\
9 .message({
10 "content": {
11 "event": "typing"
12 },
13 "sender": "Mathew.Jenkinson"
14 })\
15 .custom_message_type("typing-indicator")\
show all 16 lines1pubnub.signal(
2 channel: "my_channel",
3 message: [
4 "content": [
5 "content": [
6 "event": "typing"
7 ],
8 "sender": "Mathew.Jenkinson"
9 ]
10 ] as [String: AnyJSON],
11 customMessageType: "typing-indicator"
12) { result in
13 switch result {
14 case let .success(response):
15 print("succeeded: \(response)")
show all 19 linesChat invitation
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1JSONObject message = new JSONObject()
2 .put("content", new JSONObject()
3 .put("channel", "this is the channel you are being invited to")
4 .put("message", "Hi Craig, welcome to the team!"))
5 .put("sender", "Mathew.Jenkinson");
6
7pubnub.publish()
8 .message(message)
9 .channel("my_channel")
10 .customMessageType("chat-invitation")
11 .async(new PNCallback<PNPublishResult>() {
12 @Override
13 public void onResponse(PNPublishResult result, PNStatus status) {
14 if(!status.isError()) {
15 System.out.println("pub timetoken: " + result.getTimetoken());
show all 19 lines1pubnub.publish(
2 {
3 channel: "my_channel",
4 message: {
5 "content": {
6 "channel": "this is the channel you are being invited to",
7 "message":"Hi Craig, welcome to the team!"
8 },
9 "sender": "Mathew.Jenkinson"
10 },
11 customMessageType: "chat-invitation"
12 },
13 function(status, response) {
14 console.log(status);
15 console.log(response);
show all 17 lines1pubnub.publish(
2 message = mapOf(
3 "content" to mapOf(
4 "channel" to "this is the channel you are being invited to",
5 "message" to "Hi Craig, welcome to the team!"
6 ),
7 "sender" to "Mathew.Jenkinson"
8 ),
9 channel = "my_channel",
10 customMessageType = "chat-invitation"
11).async { result, status ->
12 if (!status.error) {
13 println("Publish timetoken ${result!!.timetoken}")
14 }
15 println("Status code ${status.statusCode}")
show all 16 lines1self.client.publish()
2 .message(@{
3 @"content": @{
4 @"channel": @"this is the channel you are being invited to",
5 @"message": @"Hi Craig, welcome to the team!"
6 },
7 @"sender": @"Mathew.Jenkinson"
8 })
9 .channel(@"my_channel")
10 .customMessageType(@"chat-invitation")
11 .performWithCompletion(^(PNPublishStatus *status) {
12 if (!status.isError) {
13 } else {
14 }
15});
1$result = $pubnub->publish()
2 ->channel("my_channel")
3 ->message([
4 "content" => [
5 "channel" => "this is the channel you are being invited to",
6 "message" => "Hi Craig, welcome to the team!"
7 ],
8 "sender" => "Mathew.Jenkinson"
9 ])
10 ->customMessageType("chat-invitation")
11 ->meta(["name" => "Alex"])
12 ->sync();
1def publish_callback(result, status):
2 if status.isError:
3 print status.statusCode
4 else:
5 print result.timetoken
6
7pubnub.publish()\
8 .channel("my_channel")\
9 .message({
10 "content": {
11 "channel": "this is the channel you are being invited to",
12 "message":"Hi Craig, welcome to the team!"
13 },
14 "sender": "Mathew.Jenkinson"
15 })\
show all 17 lines1pubnub.publish(
2 channel: "my_channel",
3 message: [
4 "content": [
5 "channel": "this is the channel you are being invited to",
6 "message": "Hi Craig, welcome to the team!"
7 ],
8 "sender": "Mathew.Jenkinson"
9 ] as [String: AnyJSON],
10 customMessageType: "chat-invitation"
11){ result in
12 switch result {
13 case let .success(response):
14 print("succeeded: \(response)")
15 case let .failure(error):
show all 18 linesVideo invitation
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1JSONObject data = new JSONObject()
2 .put("content", new JSONObject()
3 .put("session", "your-token-here"))
4 .put("sender", "Mathew.Jenkinson");
5
6pubnub.publish()
7 .message(data)
8 .channel("my_channel")
9 .customMessageType("video-invitation")
10 .async(new PNCallback<PNPublishResult>() {
11 @Override
12 public void onResponse(PNPublishResult result, PNStatus status) {
13 if(!status.isError()) {
14 System.out.println("pub timetoken: " + result.getTimetoken());
15 }
show all 18 lines1pubnub.publish(
2 {
3 channel: "my_channel",
4 message: {
5 "content": {
6 "session": "your-token-here"
7 },
8 "sender": "Mathew.Jenkinson"
9 },
10 customMessageType: "video-invitation"
11 },
12 function(status, response) {
13 console.log(status);
14 console.log(response);
15 }
show all 16 lines1pubnub.publish(
2 message = mapOf("content" to mapOf("session" to "your-token-here"), "sender" to "Mathew.Jenkinson",
3 channel = "my_channel",
4 customMessageType = "video-invitation"
5 ).async { result, status ->
6 if (!status.error) {
7 println("Publish timetoken ${result!!.timetoken}")
8 }
9 println("Status code ${status.statusCode}")
10 }
11)
1self.client.publish()
2 .message(@{
3 @"content": @{
4 @"session": @"your-token-here"
5 },
6 @"sender": @"Mathew.Jenkinson"
7 })
8 .channel(@"my_channel")
9 .customMessageType(@"video-invitation")
10 .performWithCompletion(^(PNPublishStatus *status) {
11 if (!status.isError) {
12 } else {
13 }
14});
1$result = $pubnub->publish()
2 ->channel("my_channel")
3 ->message([
4 "content" => [
5 "session" => "your-token-here"
6 ],
7 "sender" => "Mathew.Jenkinson"
8 ])
9 ->customMessageType("video-invitation")
10 ->meta(["name" => "Alex"])
11 ->sync();
1def publish_callback(result, status):
2 if status.isError:
3 print status.statusCode
4 else:
5 print result.timetoken
6
7pubnub.publish()\
8 .channel("my_channel")\
9 .message({
10 "content": {
11 "session": "your-token-here"
12 },
13 "sender": "Mathew.Jenkinson"
14 })\
15 .custom_message_type("video-invitation")\
show all 16 lines1pubnub.publish(
2 channel: "my_channel",
3 message: [
4 "content": [
5 "session": "your-token-here"
6 ],
7 "sender": "Mathew.Jenkinson"
8 ] as [String: AnyJSON],
9 customMessageType: "video-invitation"
10) { result in
11 switch result {
12 case let .success(response):
13 print("succeeded: \(response)")
14 case let .failure(error):
15 print("failed: \(error.localizedDescription)")
show all 17 linesPoll
- Java
- JavaScript
- Kotlin
- Objective-C
- PHP
- Python
- Swift
1pubnub.publish()
2 .message(new JSONObject()
3 .put("content", new JSONObject()
4 .put("question", "What do people want for lunch?")
5 .put("answers", new JSONObject()
6 .put("pizza", 0)
7 .put("pierogi", 6)
8 .put("sushi", 0)))
9 .put("sender", "Mathew.Jenkinson"))
10 .channel("my_channel")
11 .customMessageType("poll")
12 .async(new PNCallback<PNPublishResult>() {
13 @Override
14 public void onResponse(PNPublishResult result, PNStatus status) {
15 if(!status.isError()) {
show all 20 lines1pubnub.publish(
2 {
3 channel: "my_channel",
4 message: {
5 "content": {
6 "question": "What do people want for lunch?",
7 "answers": {
8 "pizza": 0,
9 "pierogi": 6,
10 "sushi": 0
11 }
12 },
13 "sender": "Mathew.Jenkinson"
14 },
15 customMessageType: "poll"
show all 24 lines1pubnub.publish(
2 message = mapOf ("content" to mapOf(
3 "question" to "What do people want for lunch?",
4 "answers" to mapOf("pizza" to 0, "pierogi" to 6, "sushi" to 0)
5 ), "sender" to "Mathew.Jenkinson"),
6 channel = "my_channel",
7 customMessageType = "poll"
8).async { result, status ->
9 if (!status.error) {
10 println("Publish timetoken ${result!!.timetoken}")
11 }
12 println("Status code ${status.statusCode}")
13}
1self.client.publish()
2 .message(@{
3 @"content": @{
4 @"question": @"What do people want for lunch?",
5 @"answers": @{
6 @"pizza": @0,
7 @"pierogi": @6,
8 @"sushi": @0
9 }
10 },
11 @"sender": @"Mathew.Jenkinson"
12 })
13 .channel(@"my_channel")
14 .customMessageType(@"poll")
15 .performWithCompletion(^(PNPublishStatus *status) {
show all 19 lines1$result = $pubnub->publish()
2 ->channel("my_channel")
3 ->message([
4 "content" => [
5 "question" => "What do people want for lunch?",
6 "answers" => [
7 "pizza" => 0,
8 "pierogi" => 6,
9 "sushi" => 0
10 ]
11 ],
12 "sender" => "Mathew.Jenkinson"
13 ])
14 ->customMessageType("poll")
15 ->meta(["name" => "Alex"])
show all 16 lines1def publish_callback(result, status):
2 if status.isError:
3 print status.statusCode
4 elif
5 print result.timetoken
6
7pubnub.publish()\
8 .channel("my_channel")\
9 .message({
10 "content": {
11 "question": "What do people want for lunch?",
12 "answers": {
13 "pizza": 0,
14 "pierogi": 6,
15 "sushi": 0
show all 21 lines1pubnub.publish(
2 channel: "my_channel",
3 message: [
4 "content": [
5 "question": "What do people want for lunch?",
6 "answers": [
7 "pizza": 0,
8 "pierogi": 6,
9 "sushi": 0
10 ]
11 ],
12 "sender": "Mathew.Jenkinson"
13 ] as [String: AnyJSON],
14 customMessageType: "poll"
15) { result in
show all 22 lines