As I did not find an occ subcommand to handle messages from within a shellscript I tried curl to get this done.
As this is my first time using webapi maybe I did not get all facts I need.
So I’m asking for help here.
As I read in https://nextcloud-talk.readthedocs.io/en/turn_doc/chat/ the base endpoint to talk is /ocs/v2.php/apps/spreed/api/v1 and before sending a message I need the token of the conversation I want to post a message.
So I tried the following commandline (masked):
curl --user <myuser>:<mypass> 'https://tcloud.mydomain.org/ocs/v2.php/apps/spreed/api/v1/room' -H "OCS-APIRequest: true"
that gave me the following result:
<?xml version="1.0"?>
<ocs>
<meta>
<status>failure</status>
<statuscode>404</statuscode>
<message>Invalid query, please check the syntax. API specifications are here: http://www.freedesktop.org/wiki/Specifications/open-collaboration-services.
</message>
</meta>
<data/>
</ocs>
What am I doing wrong here ?
2 Likes
wwe
October 17, 2022, 7:59pm
2
you are missing some required attributes… this is how it works for me:
curl -H "Content-Type: application/json" -H "Accept: application/json" -H "OCS-APIRequest: true" -v -u {user:password} -d '{"token": "{talk_conversationid}", "message":"test from linux"}' https://{mycloud.tld}/ocs/v2.php/apps/spreed/api/v1/chat/{talk_conversationid}
user:password could be “application password” for 2FA enabled users. I created a dedicated user for talk messages, enabled 2FA for this user and created app password without files access to reduce possible attack vector.
credits:
Can anyone help me with sending a new chat message using curl and API. I cannot figure out how to get the token…
Method: POST
Endpoint: /chat/{token}
https://benedikt-merz.de/Blog/?p=945
opened 10:49AM - 03 Jun 19 UTC
closed 09:51AM - 08 Aug 23 UTC
1. to develop
enhancement
high
overview
feature: chat đź’¬
feature: bots 🤖
**Is your feature request related to a problem? Please describe.**
I would like… to integrate my Smarthome System into Nextcloud Talk Chat for Notifications etc.
**Describe the solution you'd like**
Webhook Implementation (Similiar like these on Rocket.Chat/Slack etc)
Webhooks usually per Channel and multiple ones can be added for various integrations
Incoming Webhooks:
Generates an Webhook Token/Credentials to use in Scripts/Tools.
This will allow to send Messages to an specific Channel with an simple API Call. But not to read any messages for Security Reasons.
Outgoing Webhooks:
Send new Messages to an specific URL. (Standardized Format)
Optionally only if the text includes an "trigger word"
**Describe alternatives you've considered**
Currently im using an Dummy User and fake an normal "Web Client" to send Messages to an Channel. This basically works, but this User can also read Messages (Security Issue).
---
- [x] https://github.com/nextcloud/spreed/pull/9458
- [x] https://github.com/nextcloud/spreed/issues/9676
- [x] https://github.com/nextcloud/talk-ios/issues/1263
- [x] https://github.com/nextcloud/talk-android/issues/3071
1 Like
Hi wwe, thank you for the tip it works now !
1 Like