Skip to content

Instantly share code, notes, and snippets.

@balloob
Last active July 22, 2022 15:01

Revisions

  1. balloob revised this gist Nov 8, 2019. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions __init__.py
    Original file line number Diff line number Diff line change
    @@ -22,9 +22,8 @@ async def text_events(event: core.Event):
    if event.data[ATTR_CHAT_ID] != event.data[ATTR_USER_ID]:
    return

    print(event.data)
    text = event.data[ATTR_TEXT]
    response = await process(hass, text, "telegram-bot")
    response = await process(hass, event.data[ATTR_TEXT], "telegram-bot")

    await hass.services.async_call(
    TELEGRAM_DOMAIN,
    SERVICE_SEND_MESSAGE,
  2. balloob revised this gist Nov 8, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions __init__.py
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,5 @@
    # Create as custom_components/telegram_bot_conversation/__init__.py
    # Requires telegram_bot to be set up.
    from homeassistant import core
    from homeassistant.components.telegram_bot import (
    EVENT_TELEGRAM_TEXT,
  3. balloob created this gist Nov 8, 2019.
    37 changes: 37 additions & 0 deletions __init__.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    # Create as custom_components/telegram_bot_conversation/__init__.py
    from homeassistant import core
    from homeassistant.components.telegram_bot import (
    EVENT_TELEGRAM_TEXT,
    ATTR_TEXT,
    SERVICE_SEND_MESSAGE,
    DOMAIN as TELEGRAM_DOMAIN,
    ATTR_MESSAGE,
    ATTR_TARGET,
    ATTR_USER_ID,
    ATTR_CHAT_ID,
    )
    from homeassistant.components.conversation import process

    DOMAIN = "telegram_bot_conversation"


    async def async_setup(hass: core.HomeAssistant, config: dict) -> bool:
    async def text_events(event: core.Event):
    # Only deal with private chats.
    if event.data[ATTR_CHAT_ID] != event.data[ATTR_USER_ID]:
    return

    print(event.data)
    text = event.data[ATTR_TEXT]
    response = await process(hass, text, "telegram-bot")
    await hass.services.async_call(
    TELEGRAM_DOMAIN,
    SERVICE_SEND_MESSAGE,
    {
    ATTR_MESSAGE: response.speech["plain"]["speech"],
    ATTR_TARGET: event.data[ATTR_USER_ID],
    },
    )

    hass.bus.async_listen(EVENT_TELEGRAM_TEXT, text_events)
    return True
    9 changes: 9 additions & 0 deletions manifest.json
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    {
    "domain": "telegram_bot_conversation",
    "name": "Telegram Bot <> Conversation",
    "config_flow": false,
    "documentation": "",
    "requirements": [],
    "dependencies": ["telegram_bot", "conversation"],
    "codeowners": []
    }