agileek / hassio-addons

Some home assistant addons I manage
21 stars 5 forks source link

Message metadata unavailable in intent_script #54

Open bastiaanterhorst opened 1 year ago

bastiaanterhorst commented 1 year ago

Describe the bug I am using intents to trigger actions when receiving Signal messages. However, I have been unable to use any of the message metadata in these scripts. Looking through the code, it seems that several things are passed on, but I cannot seem to access these variables in my intent_script. I have tried doing so with the following syntax:

intent_script:
  Test:
    action:
      - service: script.signal_assistant
        data_template:
          sender: "{{ sender }}"

But sender remains empty.

Am I incorrect in assuming I can access these variables, am I doing something wrong, or is there a bug somewhere?

MichaelBitard commented 1 year ago

Indeed the keywords you see in the code are not variables passed on to home assistant, but are keywords the signal-cli I rely on to communicate with signal uses. It's only internal to this addon.

Home assistant receives what is passed to https://github.com/agileek/hassio-addons/blob/master/signal/root/app/ws.py#L6

I'll have to look into the intents again to see what is received by the intent, and what can be used. Could be a good opportunity to add this to the readme too

bastiaanterhorst commented 1 year ago

Ah, thank you for pointing me to that. If I read the code correctly, only the message is passed as a variable named text. I assume this is what HA internally expects to trigger intent handling. This bit:

await websocket.send(json.dumps({
                    "id": 1,
                    "type": "conversation/process",
                    "text": message,
                }))

Looking here it seems that text is the only thing to pass (assuming this websocket call triggers conversation.process internally. Looking at the source of that service, I don't think it is even possible to pass it other things unfortunately -- but I might be reading it wrong.

I will try to edit my local code and pass it some other things and see if they arrive in the intent_script, when I have a moment. I also see on that page that it should be possible to use slots to make commands variable (like 'set thermostat to 19', where 19 is a variable passed to the intent_script). I'll play with this also.

If I figure something out I'd be happy to contribute a PR to the docs to explain how to do this.