xmppSendMessage()

Sends a message over the opened clientId channel to the given recipient. The recipient is specified via the jabber id.

Synopsis

int xmppSendMessage(int clientId, string jid, string message [, mapping options [, string &id]]);

Parameter

Parameter Description
clientid The unique client id for the client channel. The id is returned by the xmppOpen() function.
jid

Jabber ID such as winccoa.etm@jabber.at. The jid can be specified with or without a resource. E.g.

winccoa.etm@jabber.at (addressing this user on any resource) or

winccoa.etm@jabber.at/mobile (only addressing this specific resource)

message The message that is sent.
options

The options mapping specifies settings for the message that is sent.

attentionRequested (bool): Sets whether the user's attention is requested when receiving the message.

receiptRequested (bool): Sets whether a delivery receipt is requested, as defined by XEP-0184: Message Delivery Receipts.

NOTE. If the attentionRequested is set to true, a message, which contains the receiptId equal to this message's id, can be received. You can return the receiptId by using the "receiptId" parameter below.

Since the client is not forced to send a receipt message, you might not receive a receipt message. Note also that if f the addressed user has multiple resources (devices) active, you might receive multiple receipt confirmation messages.

receiptId (string): If you receive a message that requires a message delivery receipt (the receiptRequested flag is true), you can reply with a receipt message by sending a message like this:

if ( message.receiptRequested )

{

xmppSendMessage(message.clientId, message.from, "", makeMapping("receiptId", message.id));

}

thread (string): Sets the message's thread.

subject (string): Sets the message's subject.

time (time): Sets the message's timestamp marking a delayed delivery according to XEP-0203

url (string): Send a URL as defined by XEP-0066. The url allows the client to open the file by downloading the given URL via an extra channel (e.g. by HTTP GET, etc.)

id The ID of the message that was sent.

Return Value

Returns 0 when the function was successfully executed or -1 in case of errors

Errors

Errors can be queried via getLastError().

Description

Sends a message over the opened clientId channel to the given recipient. The recipient is specified via the jabber id - see the parameter description above.

The following example opens the client communication channel to the jabber XMPP server, sends a message and closes the channel.

#uses "CtrlXmpp"
int p;
main(mapping event)
{
  mapping m; /* options mapping for the xmppOpen function. */
  int port;
  string host;
  string resource;
  bool autoAcceptSubscriptions = TRUE;
  string logging;
  m["host"]= host;
  m["port"] = port;
  m["resource"] = resource;
  m["autoAcceptSubscriptions"] = autoAcceptSubscriptions;
  m["logging"] = "any";
  /* Show all debug information (send, receive etc.).
  You have to activate the debug flag for the manager that executed the XMPP functions
  in order to show the debug info via the logging key. 
  See the function  xmppOpen() */
  /* Open a client communication channel to an XMPP server. */
  p = xmppOpen("winccoa.etm@jabber.at","123677", "callback", m);
  DebugN("xmppOpen:", p);
  /* Options mapping for sending a message */
  mapping mes;
  bool attentionRequested = TRUE;
  bool receiptRequested = TRUE;
  string receiptId;
  string thread;
  string subject;
  time t = getCurrentTime();
  mes["attentionRequested"] = attentionRequested;
  mes["receiptRequested"] = receiptRequested;
  mes["receiptId"] = receiptId;
  mes["thread"] = thread;
  mes["subject"] = subject;
  mes["time"] = t;
  string rID;
  /* Send the message with options attentionRequested = TRUE and receiptRequested = TRUE
  as well as the current time. The other parameters are not specified and thus the default values
  are used.*/
  int j = xmppSendMessage(p,"winccoa.etm@jabber.at", "Hello this is a new message", mes, rID);
  DebugN("Message sent:", j);
}
void callback(mapping message) /* Output the received message */
{
  DebugN("Message:", message); //The message
  dyn_string keys = mappingKeys(message);
  for(int i = 1; i <= dynlen(keys); i++)
  {
    DebugTN("key: " + keys[i] + " | type: " +getTypeName(message[keys[i]]), "value:",mappingGetValue(message,i));
  }
  if ( message.receiptRequested )
  {
    DebugN("Send confirmation to the server:", xmppSendMessage(message.clientId, message.from,"", makeMapping("receiptId", message.id)));
    DebugN("Message", message.clientId, "from:", message.from, "sent");
  }
  /* Close the connection */
  int k;
  DebugN("Close the connection:", k = xmppClose(p));
}

Assignment

XMPP functions

Availability

CTRL