METHOD_SendMessage

This method sends an instant message to a recipient.

The following table describes the parameters that you can include in this method.

Parameter

Type

Required

Description

contactId

String

√

This parameter specifies the ID of the recipient to send the message to.

message

String

√

This parameter specifies the message to send.

messageId

String

√

This parameter specifies the ID of the message created in the BlackBerry Connect app.

dependencies

String

—

This parameter specifies the other methods that this method is dependent on. It specifies the comma delimited dependent request IDs.

BEMS response and notification

The following table describes the parameters that BEMS returns and the notification to send to the BlackBerry Connect app when the user sends an instant message.

Parameter

Type

Description

timestamp Sate This parameter specifies the date that the instant message was sent. The timestamp is in Epoch UTC Unix timestamp.

method

String

This parameter specifies the invoked method (for example, SendMessage).

state String This parameter specifies the state of the request to BEMS (for example, Processing or Complete).
chatId String
This parameter specifies the ID of the chat to send the message to.
Note: For the first message, the BEMS generates a StartChat to invite the contact to accept or decline a chat.

Code sample

The following code example sends a request to BEMS to send a message to "user1".

{
  "method":"SendMessage",
  "params":
    {
     "contactId":"user1@example.com",
     "message": "Are you there?",
     "messageId":"125988FKKFJFHI2345"
    },
  "id":"c5",
  "jsonrpc":"2.0"
}

If the request is successful, BEMS sends the following response to the BlackBerry Connect app and processes the request.

{
  "id":"c5",
  "error":null,
  "result":
   {
     "data":
      {
        "timestamp":"189238873498795",
        "method": "SendMessage",
        "state":"PROCESSING"
      }
   },
  "jsonrpc":"2.0",
  "background":false
}

If there are no errors, BEMS sends the following notification and sends the message to the recipient.

{
 "id":"c5",
 "sequence":1018532000000017,
 "result":
   {
    "data":
     {
      "timestamp":"189238873498795",
      "chatId":"78bb705f-230a-45ad-9654-651f906621e1",
      "method":"SendMessage",
      "state":"COMPLETE"
     }
   },
  "jsonrpc":"2.0"
}

If the message times out or recipient declines the invitation, BEMS sends a MessageUpdate notification to the BlackBerry Connect app.

  • Sample notification if the invitation times out.
    {
      "id":"s50",
      "error":
        {
          "data":
           {
            "type":"ack",
            "status":"timeout",
            "contactIds":[sip:user1@example.com],
            "messageId":"125988FKKFJFHI2345",
            "method":"MessageUpdate"
           }
        },
      "jsonrpc":"2.0"
    }
  • Sample notification if the recipient declines the invitation.
    {
      "id":"s50",
      "error":
        {
          "data":
           {
             "type":"declined",
             "status":"terminated",
             "contactIds":[sip:user1@example.com],
             "messageId":"125988FKKFJFHI2345",
             "method":"MessageUpdate"
           }
        },
     "jsonrpc":"2.0"
    }