Ejabberd trying to subscribe a user through api

2019-08-20 12:33发布

问题:

I am trying to subscribe a test user to a test room using the Ejabberd API. I am sure I just misconfigured something but I can't seem to find the issue. I am running Ejabberd 16.09 and trying to use mod_http_api

My configuration is the following:

hosts:
  - "localhost"
  - "my.personal.host"

listen:
  -
    port: 5285
    module: ejabberd_http
    request_handlers:
      "/api": mod_http_api

acl:
  admin:
     user:
       - "@localhost"

modules:
  mod_muc:
    mam: true
    default_room_options:
      allow_subscription: true
    access:
      - allow
    access_admin:
      - allow: admin
    access_create: muc_create
    access_persistent: muc_create
  mod_muc_admin: {}
  mod_http_api:
    admin_ip_access: admin_ip_access_rule

api_permissions:
  "API used from localhost allows all calls":
    - who:
      - ip: "127.0.0.1/8"
    - what:
      - "*"
      - "!stop"
      - "!start"

access:
  admin_ip_access_rule:
    admin:
      - create_room
      - register
      - subscribe_room

I did successfully create a user test1 and a room testroom1 through the api. I then try to subscribe the user to that rum by a POST with curl:

curl -X POST -H "Cache-Control: no-cache" -d '{"user":"test1@my.personal.host/something","nick":"test1","room":"testroom1@my.persoal.host","nodes":"urn:xmpp:mucsub:nodes:messages"}' "http://localhost:5285/api/subscribe_room"

And yet I get this response:

"Subscriptions are not allowed"

So what am I doing wrong?

回答1:

Ohh, I found so many problems in your setup with just a quick look:

  1. From what I know, mod_muc doesn't have an option called 'mam'
  2. In the call, the room attribute has a spelling error when it says persoal.
  3. Also, the room JID can't be "testroom1@my.persoal.host", it may be something like "testroom1@conference.my.personal.host"

Try creating the room with a user, then check it is configured correctly (has subscriptions allowed), then try to subscribe with another account. It worked for me with this call:

$ ejabberdctl subscribe_room test2@my.personal.host Test2 testroom1@conference.my.personal.host urn:xmpp:mucsub:nodes:messages