Need help with api call to set user presence


#1

I am new to rocketchat and API calls but I was able to figure out how to make REST calls. Now I am looking to create a REALTIME call that will set a user status from Online to Away. The call is documented as this:

https://rocket.chat/docs/developer-guides/realtime-api/method-calls/user-presence/

{
“msg”: “method”,
“method”: “UserPresence:away”,
“id”: “42”,
“params”:
}

I can successfully connect to my webhook URL but I’m not sure how to use the above example to set a users presence. How do I specify a user? What is the “id” value? I see id:42 in other api examples and i’m not sure if thats just an example or if its required.


#2

I’ve tried the following, setting ‘id’ with a users “_id” and also the “id” given from LDAP. Is this supposed to be some other value? With either ID it returns {“success”:true} and posts to rocket.cat bot with “User Presence Set” but the users status is unchanged. What am I missing? Thanks!

import requests
import json

uri = 'https://domain.com/hooks/abcd/1234'
data={}
data = {
    "msg": "User Presence Set",
    "method": "UserPresence:away",
    "id": "a1b2c3d4",
    "params": []
}

r = requests.post(uri, json.dumps(data)).content
print(r)