简体   繁体   English

如何将 Django API 与 XMPP 服务器(ejabberd)集成

[英]How to integrate Django API with XMPP server (ejabberd)

I'm currently working on a project where I'm using Django rest framework (DRF) for the backend.我目前正在开发一个项目,在该项目中我使用 Django REST 框架 (DRF) 作为后端。 I need to implement one to one chat on this application.我需要在这个应用程序上实现一对一的聊天。 For this, I'm using XMPP server.为此,我正在使用XMPP服务器。 I'm using ejabberd as XMPP server.我使用ejabberd作为 XMPP 服务器。

Now, I need to create users in the ejabberd server using my API built with DRF.现在,我需要使用我用 DRF 构建的 API 在 ejabberd 服务器中创建用户。 I need to achieve following things with my API:我需要用我的 API 实现以下目标:

  • create new users in the ejabberd server在 ejabberd 服务器中创建新用户
  • create rooms in the ejabberd server在 ejabberd 服务器中创建房间
  • fetch all the available rooms.获取所有可用的房间。

The username will be fetched or retrived from the frontend.用户名将从前端获取或检索。 Is there any Python API client or Django API client to do this in the ejabberd server?在 ejabberd 服务器中是否有任何 Python API 客户端或 Django API 客户端可以执行此操作? Like how there is simple-xmpp for node js就像node jssimple-xmpp

I have seen many python packages for this.我已经为此看到了许多 python 包。 some of them are,他们之中有一些是,

I'm not sure which one to use and I don't know whether is it possible to implement the above using any of these packages.我不确定要使用哪一个,也不知道是否可以使用这些包中的任何一个来实现上述功能。

All those libraries that you mention seem to be to write XMPP clients.您提到的所有这些库似乎都是为了编写 XMPP 客户端。 In that case, you can write a small XMPP client that will attempt to register account in a xmpp server (being ejabberd or whatever), that joins a MUC room, configures it to be persistent, then requests the lists of rooms...在这种情况下,您可以编写一个小型 XMPP 客户端,该客户端将尝试在 xmpp 服务器(ejabberd 或其他)中注册帐户,加入 MUC 房间,将其配置为持久,然后请求房间列表......

A completely different approach would be to call API commands that ejabberd provides.一种完全不同的方法是调用 ejabberd 提供的 API 命令。 As you can see in the API documentation , there are commands to perform precisely what you want, and many more: register , create_room_with_opts , muc_online_rooms .正如您在API 文档中看到的那样,有一些命令可以精确地执行您想要的操作,还有更多: registercreate_room_with_optsmuc_online_rooms

And how to call this API?以及如何调用这个 API? For playing and checking what those commands do, you can use the ejabberdctl command-line script.要播放和检查这些命令的作用,您可以使用ejabberdctl命令行脚本。 Probably you will later want to use ReST (then configure mod_http_api) or XML-RPC (in that case configure ejabberd_xmlrpc).可能您稍后会想要使用 ReST(然后配置 mod_http_api)或 XML-RPC(在这种情况下配置 ejabberd_xmlrpc)。 See Understanding ejabberd commands , and also check the example configuration and example calls using curl .请参阅了解 ejabberd 命令,并使用 curl 检查示例配置和示例调用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM