powered by Jive Software

Rest API Send Messages

openfire

#1

Is there any way to send messages to specific chatroom through rest api?


#2

Summon @Redeyes to this topic :slight_smile:


#3

There is a community plugin called Chat API, which I suppose can do that: https://github.com/igniterealtime/community-plugins/wiki/Chat-API-(REST-SSE)--for-Openfire-Documentation


#4

thx for reply. we’ll try it.

Do you plan to make such functionality in your plugin?


#5

@Redeyes unfortunately it doesn’t work properly. More over it seems that works only route from your API and no more


#6

lets try to summon @Dele_Olajide as last man who made commits to ChatAPI repo

if you don’t mind I have some questions about ChatAPI:

  1. its stand alone plugin or RestApi mus be install as well?
  2. Must this route working POST to “http://mydomain:9090/plugins/restapi/v1/messages/{person/chat}”?

#7
  1. It is a standalone plugin. It does not depend on the RestApi plugin. It extends the RestApi plugin

  2. Look at the swagger UI (sandbox) in admin web console for documentation. It uses the Openfire http-bind ports (7070/7443) and not the admin (9090/9091) ports.

The version at https://github.com/igniterealtime/community-plugins is based on smack 3.x and is deprecated. I am currently working on a new version with smack 4.x and that can be found at https://github.com/deleolajide/ofmeet-openfire-plugin/tree/master/ofchat


#8

Thx @Dele_Olajide for your reply .

  1. Is this new version already support sending messages to person/chat through API?
  2. Can I find somewhere already build jar file or only source ?

#9

I build plugin from source code with NetBeans IDE. Now I have sandbox in my admin panel.
One little question what is {streamid} parameter? Or maybe there is some documentation about this?


#10

Sorry, there is no documentation yet. It is work in progress and I work on it when i get free moments from my day job. You have to read the source code for now. Look at

./ofchat/src/java/org/jivesoftware/openfire/plugin/rest/service/ChatService.java

Quick overview:

Use POST /restapi/v1/chat/{username}/login to login. It returns a stream Id. Use the stream id on any REST request that requires an authenticated user identity


#11

I appreciate for your helping me.

Can you help me a little bit more.
I successfully received streamid and send direct message to user via this route

/restapi/v1/chat/{streamid}/messages/{to}

But I have problem with sending messages to chatroom.
I use this route:

POST /restapi/v1/chat/{streamid}/rooms/{roomName}

and received an error

{
    "exception": "IllegalArgumentException",
    "message": "Exception",
    "ressource": "Exception"
}

In debug.log i have this message

2017.11.09 15:38:59 OpenfireConnection - sendRoomMessage test@conference.mydomain.com 
testMessageToChatRoomssad!!

An this what a get in error.log

Error.log

2017.11.09 15:38:59 OpenfireConnection - sendRoomMessage
java.lang.NullPointerException
at org.jivesoftware.smack.OpenfireConnection.sendRoomMessage(OpenfireConnection.java:689)
at org.jivesoftware.openfire.plugin.rest.service.ChatService.postToRoom(ChatService.java:580)
at sun.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:205)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1127)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1061)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:110)
at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:499)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:257)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:544)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555)
at java.lang.Thread.run(Thread.java:748)
2017.11.09 15:38:59 org.jivesoftware.openfire.plugin.rest.exceptions.RESTExceptionMapper - IllegalArgumentException: Exception with ressource Exception


#12

You still need to apply the rules for messaging with XMPP.

  1. You login as a user
  2. You get stream Id
  3. You join a chat room
  4. You post messages to chat room

I use the swagger UI from the chat api admin web page in openfire. It is much simpler to test the REST APIs here before committing to JavaScript


#13

Hi Cannibal

Can you please share the plugin here .

Thank you


#14

I am getting response code 500 while posting a message in the chatroom. Can you please let me know what exact parameters we need to send via swagger while creating a room and posting a message there

IllegalArgumentException: Exception with ressource Exception


#15

Join a room

Post a message to room

Message appears in chat room

Use the openfire admin web app to create the conference room or use the admin REST API