Search code examples
oauthejabberdmultiuserchatejabberd-api

How to create chat room in ejabberd through rest api?


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: {}


Solution

  • 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...