public final class JabberMethods extends Object
A TORO utility class for sending/receiving instant messages to Jabber endpoints.
Jabber an open technology for instant messaging and presence. Makes it easy to create, send or receive instant messages to a Jabber endpoint.
Modifier and Type | Method and Description |
---|---|
static JabberConnection |
createJabberConnection(String name,
Map configuration)
Creates a jabber connection based on the map configuration
|
static JabberConnection |
createJabberConnection(String name,
Map configuration,
Closure closure)
Creates a jabber connection based on the map configuration
|
static void |
jabber(String endpointName,
Closure closure)
Invoke a closure passing a
JabberConnection created from jabber connection. |
static void |
jabberChat(String endpointName,
String jid,
Closure closure)
Invoke a closure passing a
Chat created from jabber connection. |
static void |
jabberGroupchat(String endpointName,
String roomJID,
Closure closure)
Invoke a closure passing a
MultiUserChat created from jabber connection. |
static void |
sendGroupMessage(String endpointName,
String nickname,
String roomJID,
boolean leaveOnFinish,
String message)
Send group message to a chatroom.
|
static void |
sendGroupMessage(String endpointName,
String nickname,
String password,
String roomJID,
boolean leaveOnFinish,
String message)
Send group message to a chatroom.
|
static void |
sendMessage(String endpointName,
String jid,
String message)
Send a message to a user.
|
public static void sendMessage(String endpointName, String jid, String message) throws ToroException
Send a message to a user. This will reuse the Jabber connection created by the endpoint.
NOTE: Endpoint must be started before using this method
Example usage:
'endPoint'.sendMessage( 'abcd123', 'this is a sample message' )
endpointName
- endpoint name in the current packagemessage
- The message to sendjid
- jabber id of the receiverToroException
public static void jabberChat(String endpointName, String jid, Closure closure) throws ToroException
Invoke a closure passing a Chat
created from jabber connection.
NOTE: Endpoint must be started before using this method
Example usage:'endpoint'.jabberChat('123') { reply -> 'this is a sample' }
endpointName
- endpoint name in the current packagejid
- jabber id of the userclosure
- the closure to invokeToroException
public static void sendGroupMessage(String endpointName, String nickname, String roomJID, boolean leaveOnFinish, String message) throws ToroException
Send group message to a chatroom. This will reuse the Jabber connection created by the endpoint.
NOTE: Endpoint must be started before using this method
Example usage:
'endpoint'.sendGroupMessage( 'sampleNickname' , 'room1408' , true, ' this a sample message' )
endpointName
- endpoint name in the current packagenickname
- name in the chatroomroomJID
- jabber id of the chatroomleaveOnFinish
- Leave chatroom after message deliverymessage
- The message to sendToroException
public static void sendGroupMessage(String endpointName, String nickname, String password, String roomJID, boolean leaveOnFinish, String message) throws ToroException
Send group message to a chatroom. This will reuse the Jabber connection created by the endpoint.
NOTE: Endpoint must be started before using this method
Example usage:
'endpoint'.sendGroupMessage( 'john' , 'room1408' , true, ' this a sample message' )
endpointName
- endpoint name in the current packagenickname
- name in the chatroompassword
- password of the chatroomroomJID
- jabber id of the chatroomleaveOnFinish
- Leave chatroom after message deliverymessage
- The message to sendToroException
public static void jabberGroupchat(String endpointName, String roomJID, Closure closure) throws ToroException
Invoke a closure passing a MultiUserChat
created from jabber connection.
NOTE: Endpoint must be started before using this method
Example usage:
'endpoint'.sendGroupMessage( 'room1408' ) { message -> 'this is a sample message' }
endpointName
- endpoint name in the current packageroomJID
- jabber id of the chatroomclosure
- the closure to invokeToroException
public static void jabber(String endpointName, Closure closure) throws ToroException
Invoke a closure passing a JabberConnection
created from jabber connection.
WARNING: Avoid disconnecting the connection. To properly disconnect connection please stop the endpoint.
If connection is closed this attempts to reconnect the connection.
NOTE: Endpoint must be started to use jabber connection
Example usage:
'endpoint'.jabber( ) { message -> 'this is a sample message' }
endpointName
- endpoint name in the current packageclosure
- The closure to execute, with the JabberConnection being passed inToroException
public static JabberConnection createJabberConnection(String name, Map configuration, Closure closure) throws ToroException
Creates a jabber connection based on the map configuration
Example usage:
Map configuration = [ serviceName : 'sampleService' , username: 'toro', password: 'toro'] def jabberConnection = 'example'.createJabberConnection( configuration ) { message -> 'this is a sample' }
name
- name of the connection to be createdconfiguration
- configuration for jabber connectionclosure
- do more stuff on jabber connection (eg. send a message )JabberConnection
ToroException
JabberConnection.buildConfiguration(Map)
public static JabberConnection createJabberConnection(String name, Map configuration) throws ToroException
Creates a jabber connection based on the map configuration
Example usage:
Map configuration = [ serviceName : 'sampleService' , username: 'toro', password: 'toro'] def jabberConnection = 'example'.createJabberConnection( configuration )
name
- name of the connection to be createdconfiguration
- configuration for jabber connectionJabberConnection
ToroException
JabberConnection.buildConfiguration(Map)
Copyright © 2019. All rights reserved.