如何通过rest api在ejabberd中创建聊天室?

How to create chat room in ejabberd through rest api?

我知道我可以使用命令在 ejabberd 中创建聊天室

ejabberdctl create_room room_name muc_service xmpp_domain

我可以使用命令向用户发送邀请

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

并且还使用

在 ejabberd.yml 文件中启用了 mod_muc_admin

modules: mod_muc_admin: {}

要执行 api 创建房间的请求,

卷曲post,

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"

使用 mod_restful 模块通过 api 访问 ejabberd。如果您想访问该模块,您需要在 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,您可以使用 postman 或 curl

访问 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...