2

I know that I can create chat room in ejabberd using command

ejabberdctl create_room room_name muc_service xmpp_domain

and I can send invites to users using command

ejabberdctl send_direct_invitation room_name password reason jid1[:jid2]

Can someone tell me how to do the same using ejabberd rest api ?

I'm using oauth for authentication.

I've done following configuration in ejabberd.yml file

port: 5280 module: ejabberd_http request_handlers: "/websocket": ejabberd_http_ws "/log": mod_log_http "/oauth": ejabberd_oauth "/api": mod_http_api web_admin: true http_bind: true register: true captcha: true commands_admin_access: configure commands: - add_commands: - user - status oauth_expire: 3600 oauth_access: all

and also enabled mod_muc_admin in ejabberd.yml file using

modules: mod_muc_admin: {}

Ankit
  • 326
  • 1
  • 7
  • 18

2 Answers2

3

Use mod_restful module for accessing ejabberd through api. You need to configure below lines in ejabberd.yml if you want to access that module.

mod_restful:
api:
  - path: ["admin"]
    module: mod_restful_admin
    params:
      key: "secret"
      allowed_commands: [register, unregister,status, add_rosteritem, create_room, send_direct_invitation, set_room_affiliation]
  - path: ["register"]
    module: mod_restful_register
    params:
      key: "secret"

They commands that are declared in allowed_commands, only those commands are accessible through api. So in future if you want to access any other commands you need to add here.

once you finished adding ,restart ejabberd and you can access api either with postman or with curl

/* 
            Data that need to be sent for creating group.

            Url : example.com:8088/api/admin/
            Content-Type: application/json

            {"key": "secret","command": "create_room","args": ["group1","conference.example.com","example.com"]}


*/

Similar like this try for send_direct_invitation too...

Mani Kandan
  • 699
  • 1
  • 10
  • 30
  • 1
    where should I write these settings, i.e., under modules or somewhere else in ejabberd.yml file. Further, what does this "key" : "secret" mean, should I send it as it is, actually I'm using oauth, so how can I use it here. – Ankit Jul 25 '16 at 13:01
  • you need to add this in ejabberd.yml under modules section and key is used for authentication purpose such that to know whether the right person is accessing this port . You can change the value of key by changing the value in ejabberd.yml. – Mani Kandan Jul 25 '16 at 16:05
  • @ManiKandan which ejabberd version have you used with the above config ? – Jubayer Arefin Dec 14 '16 at 04:20
  • ejabberd version is 16.04.43 – Mani Kandan Dec 15 '16 at 05:15
0

To do the api request to create a room,

Do a curl post,

curl -X POST -H "Cache-Control: no-cache" -d '{ "name": "aaaaa", "service": "bbbbb", "host": "ccccc" }' "http://localhost:5280/api/create_room"

Or if you want to add multiple room in a single stoke, add all the room names in a file, say the file name is aaaaa

do a curl as this,

curl -X POST -H "Cache-Control: no-cache" -d '{ "file": "aaaaa" }' "http://localhost:5280/api/create_rooms_file"

  • Using 5280 port is okay, but the same port can be accessed in webpanel too so configuring mod_resful which uses port 8088 for api's is recommendable . – Mani Kandan Jul 25 '16 at 08:35