如何通过rest api在ejabberd中创建聊天室?
我知道我可以使用命令如何通过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: {}
使用通过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太...
在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"
使用5280端口是好的,但同样的端口也可以在webpanel中访问,所以配置使用端口8088 for api的mod_resful是值得推荐的。 –
我应该在哪里写这些设置,即,在模块或ejabberd.yml文件别处。此外,这个“关键”是什么:“秘密”是指我应该发送它,实际上我使用oauth,所以我怎么在这里使用它。 – Ankit
需要在ejabberd.yml下模块中添加该和密钥用于认证目的,从而知道正确的人是否正在访问此端口。您可以通过更改ejabberd.yml中的值来更改键的值。 –
@ ManiKandan ejabberd版本你有没有使用上述配置? –