Following the last post, where I shared how to use Telegram’s bot; on this post I’m going to explain how implement it by Chat Nextcloud API. This post is useful for those have a Nexctcloud deployment running at home/cloud.

Assuming you have already Nextcloud up and running, we can create the new user, that we are gonna use it as “BOT” we will need the chat room token and the “BOT” credentials.

The Talk app I have installed is 10.0.1 you can check it by your app repository from your administrator account or by the following command through Nextcloud server app:

$ php /var/www/html/occ app:list | grep "spreed"
  - spreed: 10.0.1
  1. Create a new room chat between you and your “BOT”, it will give you the token, eg: https://hostname.domain/call/tokenid
  2. Test it by curl the API response, thus the REST API it will be something like:

https://host.domain/ocs/v2.php/apps/spreed/api/v1/chat/tokenid

I tested it sending a message by the following POST method:

curl -d '{"token":"tokenid", "message":"hello world"}' -H "Content-Type: application/json" -H "Accept:application/json" -H "OCS-APIRequest:true" -u "user:password" https://host.domain/ocs/v1.php/apps/spreed/api/v1/chat/tokenid 2> /dev/null | > /dev/null

remembers the: OCS-APIRequest:true flag more info over –> here

  1. Create your own script

Below it will be the script where we can call in order to send whenever we want to sent

eg:

$ nano sender.sh

Copy, and fill it with your own data:

#!/bin/bash

API=https://hostname.domain.com/ocs/v2.php/apps/spreed/api/v1/chat/tokenid
LOGIN="user:password"
MESSAGE=$1

curl -d '{"token":"xxxxxxxx", "message":"'"$MESSAGE"'"}' -H "Content-Type: application/json" -H "Accept:application/json" -H "OCS-APIRequest:true" -u "$LOGIN" $API 2> /dev/null | > /dev/null

Set the execution permission

$ chmod 755 sender.sh

Now we can test it:

$ ./sender.sh "Hello Word"