2016-07-23 80 views
0

我知道我可以使用命令如何通過rest api在ejabberd中創建聊天室?

ejabberdctl create_room room_name muc_service xmpp_domain

創建ejabberd聊天室,我可以使用命令

發送邀請給用戶ejabberdctl send_direct_invitation room_name password reason jid1[:jid2]

有人能告訴我如何做同樣的使用ejabberd rest api?

我使用OAuth進行身份驗證。

我已經做了下面的配置,ejabberd.yml文件

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

,並使用

modules: mod_muc_admin: {}

回答

1

使用通過API訪問ejabberd mod_restful模塊。如果您想訪問該模塊,則需要在ejabberd.yml的下面幾行進行配置。

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" 

它們在allowed_commands中聲明的命令,只有那些命令可以通過api訪問。所以在未來,如果你想訪問任何其他命令,你需要在這裏添加。

一旦你添加完,重新啓動ejabberd,你可以訪問API或者與郵差或捲曲

/* 
      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"]} 


*/ 

類似這樣的嘗試send_direct_invitation太...

+0

我應該在哪裏寫這些設置,即,在模塊或ejabberd.yml文件別處。此外,這個「關鍵」是什麼:「祕密」是指我應該發送它,實際上我使用oauth,所以我怎麼在這裏使用它。 – Ankit

+0

需要在ejabberd.yml下模塊中添加該和密鑰用於認證目的,從而知道正確的人是否正在訪問此端口。您可以通過更改ejabberd.yml中的值來更改鍵的值。 –

+0

@ ManiKandan ejabberd版本你有沒有使用上述配置? –

0

在ejabberd.yml文件中啓用mod_muc_admin要做到的API請求創建一個房間,

做捲曲後,

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

或者,如果你想在一個單一的行程中添加多個房間,加上所有的房間名稱的文件,說文件名是aaaaa

做捲曲,因爲這,

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

+0

使用5280端口是好的,但同樣的端口也可以在webpanel中訪問,所以配置使用端口8088 for api的mod_resful是值得推薦的。 –