Skip to content

Example WebSocket Messages

Mike Angstadt edited this page Sep 3, 2017 · 9 revisions

New message

{
  "r1" : {
    "e" : [
      {
        "event_type" : 1,
        "time_stamp" : 1498317444,
        "content" : "test",
        "id" : 76625573,
        "user_id" : 13379,
        "user_name" : "Michael",
        "room_id" : 1,
        "room_name" : "Sandbox",
        "message_id" : 37799434
      }
    ],
    "t" : 76625573,
    "d" : 1
  }
}

Message edited

(event type = 2)

{
  "r1" : {
    "e" : [
      {
        "event_type" : 2,
        "time_stamp" : 1498317513,
        "content" : "test4",
        "id" : 76625602,
        "user_id" : 13379,
        "user_name" : "Michael",
        "room_id" : 1,
        "room_name" : "Sandbox",
        "message_id" : 37799446,
        "message_edits" : 1
      }
    ],
    "t" : 76625602,
    "d" : 1
  }
}

Message deleted

{
  "r1" : {
    "e" : [
      {
        "event_type" : 10,
        "time_stamp" : 1498317513,
        "id" : 76625609,
        "user_id" : 13379,
        "user_name" : "Michael",
        "room_id" : 1,
        "room_name" : "Sandbox",
        "message_id" : 37799446,
        "message_edits" : 1
      }
    ],
    "t" : 76625609,
    "d" : 1
  }
}

A message was replied to

An event with an event_type of 18 gets broadcast to all rooms the user is in. In addition to this, a "new message" event gets sent to the room the message was posted in.

{
  "r1" : {
    "e" : [ {
      "event_type" : 18,
      "time_stamp" : 1500148961,
      "content" : "@OakBot Test2",
      "id" : 77322110,
      "user_id" : 13379,
      "target_user_id" : 4258326,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38145271,
      "parent_id" : 38145269,
      "show_parent" : true
    }, {
      "event_type" : 1,
      "time_stamp" : 1500148961,
      "content" : "@OakBot Test2",
      "id" : 77322111,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38145271,
      "parent_id" : 38145269,
      "show_parent" : true
    } ],
    "t" : 77322111,
    "d" : 2
  },
  "r139" : {
    "e" : [ {
      "event_type" : 18,
      "time_stamp" : 1500148961,
      "content" : "@OakBot Test2",
      "id" : 77322110,
      "user_id" : 13379,
      "target_user_id" : 4258326,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38145271,
      "parent_id" : 38145269,
      "show_parent" : true
    } ],
    "t" : 77322111,
    "d" : 2
  }
}

If a reply was added to an existing message via an edit, then instead of a "new message" event being posted, a "message edited" event is posted (event_type = 2).

{
  "r1" : {
    "e" : [ {
      "event_type" : 18,
      "time_stamp" : 1500669165,
      "content" : "@OakBot test",
      "id" : 77539939,
      "user_id" : 13379,
      "target_user_id" : 4258326,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38259191,
      "parent_id" : 38259179,
      "message_edits" : 1,
      "show_parent" : true
    }, {
      "event_type" : 2,
      "time_stamp" : 1500669165,
      "content" : "@OakBot test",
      "id" : 77539940,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38259191,
      "parent_id" : 38259179,
      "message_edits" : 1,
      "show_parent" : true
    } ],
    "t" : 77539943,
    "d" : 5
  }
}

A user was mentioned in a message

If multiple mentions exist in the message, only the first mention is considered.

An event with an event_type of 8 gets broadcast to all rooms the user is in. In addition to this, a "new message" event gets sent to the room the message was posted in.

{
  "r1" : {
    "e" : [ {
      "event_type" : 8,
      "time_stamp" : 1500332101,
      "content" : "One @Oak two @Steven",
      "id" : 77380914,
      "user_id" : 13379,
      "target_user_id" : 4258326,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38175407
    }, {
      "event_type" : 1,
      "time_stamp" : 1500332101,
      "content" : "One @Oak two @Steven",
      "id" : 77380916,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38175407
    } ],
    "t" : 77380916,
    "d" : 3
  },
  "r23262" : {
    "e" : [ {
      "event_type" : 8,
      "time_stamp" : 1500332101,
      "content" : "One @Oak two @Steven",
      "id" : 77380914,
      "user_id" : 13379,
      "target_user_id" : 4258326,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38175407
    } ],
    "t" : 77380916,
    "d" : 3
  }
}

Message was starred (or unstarred)

{
  "r1" : {
    "e" : [ {
      "event_type" : 6,
      "time_stamp" : 1493352001,
      "content" : "<i>&quot;If you don&#39;t have confidence, you&#39;ll always find a way not to win&quot;</i> -Carl Lewis <a href=\"https://theysaidso.com/quote/4sjGQiAAZhY6jCxr6XcV1QeF/carl-lewis-if-you-dont-have-confidence-youll-always-find-a-way-not-to-win\" rel=\"nofollow noopener noreferrer\">(source)</a>",
      "id" : 77380798,
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 36846665,
      "message_stars" : 3
    } ],
    "t" : 77380798,
    "d" : 1
  }
}

Messages moved to another room

{
  "r1" : {
    "e" : [ {
      "event_type" : 19,
      "time_stamp" : 1500664511,
      "content" : "one",
      "id" : 77537961,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38258010,
      "moved" : true
    }, {
      "event_type" : 19,
      "time_stamp" : 1500664518,
      "content" : "two",
      "id" : 77537963,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38258015,
      "moved" : true
    }, {
      "event_type" : 19,
      "time_stamp" : 1500664519,
      "content" : "three",
      "id" : 77537965,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38258017,
      "moved" : true
    }, {
      "event_type" : 1,
      "time_stamp" : 1500664587,
      "content" : "&rarr; <i><a href=\"http://chat.stackoverflow.com/transcript/message/38258010#38258010\">3 messages</a> moved to <a href=\"http://chat.stackoverflow.com/rooms/48058/trash\">Trash</a></i>",
      "id" : 77537967,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox",
      "message_id" : 38258054
    } ],
    "t" : 77537970,
    "d" : 10
  }
}

Messages moved from another room

{
  "r145262" : {
    "e" : [ {
      "event_type" : 20,
      "time_stamp" : 1500669104,
      "content" : "/shutdown",
      "id" : 77554329,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 145262,
      "room_name" : "Bot sandbox",
      "message_id" : 38259178,
      "moved" : true
    }, {
      "event_type" : 20,
      "time_stamp" : 1500669106,
      "content" : "Shutting down. See you later.",
      "id" : 77554331,
      "user_id" : 4258326,
      "user_name" : "OakBot",
      "room_id" : 145262,
      "room_name" : "Bot sandbox",
      "message_id" : 38259179,
      "moved" : true
    }, {
      "event_type" : 20,
      "time_stamp" : 1500669165,
      "content" : "@OakBot test",
      "id" : 77554333,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 145262,
      "room_name" : "Bot sandbox",
      "message_id" : 38259191,
      "parent_id" : 38259179,
      "message_edits" : 1,
      "show_parent" : true,
      "moved" : true
    }, {
      "event_type" : 1,
      "time_stamp" : 1500687220,
      "content" : "&larr; <i>3 messages moved from <a href=\"http://chat.stackoverflow.com/rooms/1/sandbox\">Sandbox</a></i>",
      "id" : 77554335,
      "user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 145262,
      "room_name" : "Bot sandbox",
      "message_id" : 38262772
    } ],
    "t" : 77554335,
    "d" : 8
  }
}

User entered room

{
  "r1" : {
    "e" : [ {
      "event_type" : 3,
      "time_stamp" : 1500331806,
      "id" : 77380786,
      "user_id" : 13379,
      "target_user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox"
    } ],
    "t" : 77380786,
    "d" : 1
  }
}

User left room

{
  "r1" : {
    "e" : [ {
      "event_type" : 4,
      "time_stamp" : 1500331721,
      "id" : 77380764,
      "user_id" : 13379,
      "target_user_id" : 13379,
      "user_name" : "Michael",
      "room_id" : 1,
      "room_name" : "Sandbox"
    } ],
    "t" : 77380764,
    "d" : 11
  }
}

Room name and/or description changed

Note that the "content" field begins with the new room name, followed by a slash, followed by the room description.

{
  "r19132" : {
    "e" : [ {
      "event_type" : 5,
      "time_stamp" : 1503687307,
      "content" : "Android Era with Kotlin and Java / Important: Read dos and don&#39;ts here: https://goo.gl/TQ5Gww . Mark this room as your favorite to stay in touch with! :)",
      "id" : 78734364,
      "user_id" : 3968793,
      "user_name" : "ballBreaker",
      "room_id" : 19132,
      "room_name" : "Android Era with Kotlin and Java"
    }],
    "t" : 77380764,
    "d" : 11
  }
}

User invited you to join a room

{
  "r139" : {
    "e" : [ {
      "event_type" : 17,
      "time_stamp" : 1502501805,
      "content" : "<a href=\"/users/13379/michael\">Michael</a> has invited you to join <a href=\"/rooms/48058/trash\" target=\"_self\">Trash</a>. See your <a href=\"/rooms?tab=invited\">invitations</a>.",
      "id" : 78285636,
      "user_id" : 13379,
      "target_user_id" : 4258326,
      "user_name" : "Michael",
      "room_id" : 48058,
      "room_name" : "Trash"
    }],
    "t" : 77380764,
    "d" : 11
  }
}

Event announcement

{
  "r1" : {
    "e" : [ {
      "event_type" : 14,
      "time_stamp" : 1502408842,
      "content" : "An event is starting in 12 minutes in <a href=\"/rooms/138515/friends-family\">Friends &amp; Family</a> - &quot;Songs&quot;",
      "id" : 78241112,
      "user_id" : -2,
      "user_name" : "Feeds",
      "room_id" : 138515,
      "room_name" : "Friends & Family"
    }],
    "t" : 77380764,
    "d" : 11
  }
}

User made room owner

The "user_name" and "user_id" fields refer to the person who is doing the promoting. The "target_user_id" field is the new room owner.

{
  "r138515" : {
    "e" : [ {
      "event_type" : 15,
      "time_stamp" : 1501853150,
      "content" : "Access now owner",
      "id" : 78026296,
      "user_id" : 2585989,
      "target_user_id" : 6315209,
      "user_name" : "AmeeJoshi",
      "room_id" : 138515,
      "room_name" : "Room for Amee Joshi and Chewbacco Cat"
    } ],
    "t" : 77380764,
    "d" : 11
  }
}