create a function which sends an xmpp message of user input in r

library(xmpp)
client <- function(jid, pwd) {

   # create connection
   conn <- jabber(jid, pwd, verbose = FALSE)

   # function to send xmpp message
   send_message <- function(to, message) {
      msg <- message(type = "chat", to = to, body = message)
      send(conn, msg)
   }

   # return the send_message function
   return(send_message)
}
346 chars
16 lines

This code defines a function client that takes a jabber ID and password as inputs, creates an xmpp connection using the jabber function from the xmpp library, and returns a send_message function. The send_message function takes two arguments: to (the jabber ID of the message recipient) and message (the text to send). The message function from the xmpp library is used to create the message, and the send function is used to send it through the xmpp connection.

This allows you to create a client and send xmpp messages in R as follows:

# create client with jabber ID and password
my_client <- client("my_jabber_id@jabber.org", "my_password")

# use the send_message function to send a message
my_client("recipient_jabber_id@jabber.org", "Hello, world!")
218 chars
6 lines

related categories

gistlibby LogSnag