klatka / nc-talk-bot-component

Custom component for Home Assistant to communicate between Home Assistant and Nextcloud Talk
Apache License 2.0
11 stars 0 forks source link
hacs hacs-integration home-assistant homeassistant-custom-component nextcloud nextcloud-talk nextcloud-talk-bot nextcloud-talk-chat-bot notify

Nextcloud Talk Bot

hacs_badge Version

Custom component for Home Assistant to communicate between Home Assistant and Nextcloud Talk.

What can I do with this component?

You can choose if you want to communicate one way or in both ways.

Requirements

The base endpoint is: /ocs/v2.php/apps/spreed/api/v1 (requires the bots-v1 capability - available since Nextcloud 27.1).

Installation

Preparation

Install this component in Home Assistant:

Method 1: Send messages only (One-way HA > NC)

Method 1: Step 1

Method 1: Step 2

Create a bot in Nextcloud Talk (see nextcloud docs):

Method 1: Step 3

Method 2: React to messages (Two-way HA <> NC or One-way NC > HA)

Method 2: Step 1

Method 2: Step 2

Create a bot in Nextcloud Talk (see nextcloud docs):

Method 2: Step 3 (Optional)

Send message

Use service notify.nctalkbot:

service: notify.nctalkbot
data:
  message: Test from Home Assistant

If you want to target another room, you can set the room token like this:

service: notify.nctalkbot
data:
  message: Test from Home Assistant
  target: <room-token>

Note: The bot must be assigned to your target room!

React to message

Every time something happens in the Nextcloud Talk room, the webhook will be triggered. After verifying that this is a valid message from an authorized bot the event nctalkbot_webhook_received will be fired.

The content of the fired event looks like this:

event_type: nctalkbot_webhook_received
data:
  type: Create
  actor:
    type: Person
    id: users/kevin.latka
    name: Kevin Latka
  object:
    type: Note
    id: "807"
    name: message
    content: "{\"message\":\"I love this component\",\"parameters\":[]}"
    mediaType: text/markdown
  target:
    type: Collection
    id: f7wt6tng
    name: nctalkbot
  rendered_content: I love this component
  webhook_id: bdb898075abcf8214e5a296d7f3f0d516c69c986638ab92f7baa8e929670f7bb
origin: LOCAL
time_fired: "2023-10-26T16:29:23.417885+00:00"
context:
  id: 01HDPD3C2S6C6BAEVMMRH8N18N
  parent_id: null
  user_id: null

At this point, you can create plenty of automation for this webhook event (see docs):

Buy Me a Coffee