Skip to content

Messages

Kason Chan edited this page Jun 16, 2015 · 6 revisions

Messages are the basic atomic building block of all things PlayChat.

Field guide

Field Type Description
owner String The user-defined login, handle, or alias that indicating who sent this message.
Valid length range: 1 - 50.
Example: "owner": "playchatapi"
users Seq[String] Sequence of current room users, limited to 100 users.
Example: "users": "["a", "playchatapi"]"
reads Seq[User] Sequence of current room users, limited to 100 users.
When true, indicates that the user has read the message.
Example: "users": [ { "login" : "a", "read" : true }, { "login" : "playchat", "read" : true } ]
coordinates Coordinates Represents the geographic location of this message as reported by the user application. The inner coordinates array is formatted as latitude first, then longitude.
Optional.
Example: "coordinates": { }
text String The actual UTF-8 text of the message.
Valid length range: 1 - 1000.
Example: "text": "Hello world!"
created_at Long The system datetime that the message was created on PlayChat.
Example: "created_at": 1432441527583
updated_at Long The system datetime that the room was updated on PlayChat.
Example: "updated_at": 1432441527583
User
Field Type Description
login String The user-defined login, handle, or alias that this user identifies themselves with.
Logins are unique.
Valid length range: 1 - 50.
Example: "login": "playchatapi"
read Boolean When true, indicates that the user has read the message.
Default to false.
Example: "read": true
Coordinates
Field Type Description
coordinates Seq[Double] The latitude and longitude of the message’s location, as an sequence in the form of [latitude, longitude].
Example: "coordinates": [0.0, 0.0]

Get user messages

Get all messages for the authenticated user

You must pass authentication information with your request.

Request
Route
GET /users/:username/messages
Response
Status
200 OK
Body
[ {
  "owner": "playchatapi",
  "users": [
    "a",
    "playchat"
  ],
  "reads": [ {
    "login": "a",
    "read": true 
  }, {
    "login": "playchat",
    "read": true
  } ],
  "coordinates": {
    "coordinates": { }
  }
  "created_at": 1432441529876,
  "updated_at": 1432441529876
} ]

Get specified room messages

Get all specified room messages for the authenticated user

You must pass authentication information with your request.

Request
Route
POST /user/room/messages
Body
{ 
  "users": [ 
    "a",
    "b" 
  ] 
}
Response
Status
200 OK
Body
[ {
  "owner": "a",
  "users": [
    "a",
    "b"
  ],
  "reads": [ {
    "login": "a",
    "read": true 
  }, {
    "login": "b",
    "read": true
  } ],
  "coordinates": {
    "coordinates": { }
  }
  "created_at": 1432441584799,
  "updated_at": 1432441619287
} ]

Create

Create a new message for the authenticated user

You must pass authentication information with your request.

Request
Route
POST /user/messages
Body
{ 
  "owner": "a",
  "users": [ 
    "a", 
    "b" 
  ],
  "text": "Hi, this is A with coords.",
  "coordinates": { 
    "coordinates": [
      -34.397, 
      150.644
    ] 
  } 
}
Response
Status
201 Created
Body
{ 
  "owner": "a",
  "users": [ 
    "a", 
    "b" 
  ],
  "reads": [ { 
    "login": "a",
    "read": true
  }, { 
    "login": "b",
    "read": false
  } ],
  "text": "Hi, this is A with coords.",
  "coordinates": { 
    "coordinates": [
      -34.397, 
      150.644
    ] 
  }
  "created_at": 1432441584799,
  "updated_at": 1432441584799 
}
Clone this wiki locally