Block Libraries Telegram Actions chat ID

Hi everybody

First of all, many thanks to all developers and contributors for the fantastic work on OH 3.
Im now on OH 3.2 and review all my rules and migrate to UI rules and blockly.
One of my first rules include telegram actions, and i didn’t get it working with blockly because of the chat ID.
As @ysc and @stefan.hoehn did a great job on the blockly reference and How To Write Block Libraries
i took the original block and added the chat ID field. I did some tests an it’s working, but as i’m not a programmer, could anybody review the code.

uid: telegram_mod
props:
  parameters: []
  parameterGroups: []
timestamp: Dec 31, 2021, 8:03:42 PM
component: BlockLibrary
config:
  name: Telegram with ChatID
slots:
  blocks:
    - component: BlockType
      config:
        args0:
          - name: MESSAGE
            type: input_value
          - name: BOT
            type: input_value
          - name: CHAT_ID
            type: input_value
        colour: "#2ea5d8"
        helpUrl: ""
        inputsInline: true
        lastDummyAlign0: right
        message0: send on Telegram %1 from bot %2 with chat id %3
        nextStatement: ""
        previousStatement: ""
        tooltip: ""
        type: message
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: >
                {{utility:things}}.getActions('telegram', {{input:BOT}}).sendTelegram({{input:CHAT_ID}}, {{input:MESSAGE}});
        toolbox:
          - component: PresetInput
            config:
              fields:
                TEXT: What's up?
              name: MESSAGE
              shadow: true
              type: text
          - component: PresetInput
            config:
              name: BOT
              shadow: true
              type: oh_thing
          - component: PresetInput
            config:
              fields:
                NUM: 123
              name: CHAT_ID
              shadow: true
              type: math_number
    - component: BlockType
      config:
        args0:
          - name: ATTACHMENT_TYPE
            type: field_dropdown
            align: right
            options:
              - - photo
                - Photo
              - - animation
                - Animation
              - - video
                - Video
          - name: URL
            type: input_value
            align: right
          - name: CAPTION
            type: input_value
            align: right
          - name: BOT
            type: input_value
            align: right
          - name: CHAT_ID
            type: input_value
            align: right
        lastDummyAlignRight0: true
        colour: "#2ea5d8"
        helpUrl: ""
        inputsInline: false
        lastDummyAlign0: right
        message0: send %1 on Telegram %2 with caption %3 from bot %4 with chat id %5
        nextStatement: ""
        previousStatement: ""
        tooltip: ""
        type: message_attachment
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: >
                {{utility:things}}.getActions('telegram', {{input:BOT}}).sendTelegram({{input:CHAT_ID}}, {{field:ATTACHMENT_TYPE}}({{input:URL}}, {{input:CAPTION}}));
        toolbox:
          - component: PresetInput
            config:
              fields:
                TEXT: URL or filename
              name: URL
              shadow: true
              type: text
          - component: PresetInput
            config:
              fields:
                TEXT: caption
              name: CAPTION
              shadow: true
              type: text
          - component: PresetInput
            config:
              name: BOT
              shadow: true
              type: oh_thing
          - component: PresetInput
            config:
              fields:
                NUM: 123
              name: CHAT_ID
              shadow: true
              type: math_number
    - component: BlockType
      config:
        args0:
          - name: URL
            type: input_value
            align: right
          - name: USERNAME
            type: input_value
            align: right
          - name: PASSWORD
            type: input_value
            align: right
          - name: CAPTION
            type: input_value
            align: right
          - name: BOT
            type: input_value
            align: right
          - name: CHAT_ID
            type: input_value
            align: right
        lastDummyAlignRight0: true
        colour: "#2ea5d8"
        helpUrl: ""
        inputsInline: false
        lastDummyAlign0: right
        message0: send photo on Telegram %1 username %2 password %3 with caption %4 from bot %5 with chat id %6
        nextStatement: ""
        previousStatement: ""
        tooltip: ""
        type: message_attachment_photo_with_creds
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: >
                {{utility:things}}.getActions('telegram', {{input:BOT}}).sendTelegramPhoto({{input:CHAT_ID}}, {{input:URL}}, {{input:CAPTION}}, {{input:USERNAME}}, {{input:PASSWORD}});
        toolbox:
          - component: PresetInput
            config:
              fields:
                TEXT: URL or filename
              name: URL
              shadow: true
              type: text
          - component: PresetInput
            config:
              fields:
                TEXT: caption
              name: CAPTION
              shadow: true
              type: text
          - component: PresetInput
            config:
              fields:
                TEXT: user
              name: USERNAME
              shadow: true
              type: text
          - component: PresetInput
            config:
              fields:
                TEXT: pass
              name: PASSWORD
              shadow: true
              type: text
          - component: PresetInput
            config:
              name: BOT
              shadow: true
              type: oh_thing
          - component: PresetInput
            config:
              fields:
                NUM: 123
              name: CHAT_ID
              shadow: true
              type: math_number
    - component: Separator
      config:
        gap: 48
    - component: BlockType
      config:
        args0:
          - name: MESSAGE
            type: input_value
            align: right
          - name: BOT
            type: input_value
            align: right
          - name: REPLY_ID
            type: input_value
            align: right
          - name: CHAT_ID
            type: input_value
            align: right
          - name: BUTTONS
            type: field_input
            align: right
        lastDummyAlignRight0: true
        colour: "#2ea5d8"
        helpUrl: ""
        inputsInline: false
        lastDummyAlign0: right
        message0: ask on Telegram %1 from bot %2 use reply id %3 with chat id %4 with buttons %5
        nextStatement: ""
        previousStatement: ""
        tooltip: ""
        type: query
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: >
                {{utility:things}}.getActions('telegram', {{input:BOT}}).sendTelegramQuery({{input:CHAT_ID}}, {{input:MESSAGE}}, {{input:REPLY_ID}}, {{field:BUTTONS}});
        toolbox:
          - component: PresetInput
            config:
              fields:
                TEXT: Turn off the lights?
              name: MESSAGE
              shadow: true
              type: text
          - component: PresetField
            config:
              name: BUTTONS
              value: "'Yes', 'No'"
          - component: PresetInput
            config:
              fields:
                TEXT: replyId
              name: REPLY_ID
              shadow: true
              type: text
          - component: PresetInput
            config:
              name: BOT
              shadow: true
              type: oh_thing
          - component: PresetInput
            config:
              fields:
                NUM: 123
              name: CHAT_ID
              shadow: true
              type: math_number
    - component: BlockType
      config:
        args0:
          - name: MESSAGE
            type: input_value
            align: right
          - name: REPLY_ID
            type: input_value
            align: right
          - name: BOT
            type: input_value
            align: right
          - name: CHAT_ID
            type: input_value
            align: right
        lastDummyAlignRight0: true
        colour: "#2ea5d8"
        helpUrl: ""
        inputsInline: false
        lastDummyAlign0: right
        lastDummyAlign1: right
        message0: reply on Telegram %1 to reply id %2 from bot %3 with chat id %4
        nextStatement: ""
        previousStatement: ""
        tooltip: ""
        type: answer
      slots:
        code:
          - component: BlockCodeTemplate
            config:
              template: >
                {{utility:things}}.getActions('telegram', {{input:BOT}}).sendTelegramAnswer({{input:CHAT_ID}}, {{input:REPLY_ID}}, {{input:MESSAGE}});
        toolbox:
          - component: PresetInput
            config:
              fields:
                TEXT: Ok!
              name: MESSAGE
              shadow: true
              type: text
          - component: PresetInput
            config:
              fields:
                TEXT: replyId
              name: REPLY_ID
              shadow: true
              type: text
          - component: PresetInput
            config:
              name: BOT
              shadow: true
              type: oh_thing
          - component: PresetInput
            config:
              fields:
                NUM: 123
              name: CHAT_ID
              shadow: true
              type: math_number
  utilities:
    - component: UtilityJavaType
      config:
        javaClass: org.openhab.core.model.script.actions.Things
        name: things

all the best and a happy new year

Rolli

Looks great, but if you clone something that you imported from the marketplace, I’d advise you to remove the tag with the marketplace add-on ID (line 3) and also copy the entire code in another block library using another uid (on line 1). The tag is used to report it as “installed” in the add-on store, and if for any reason the add-on is uninstalled from there, it will effectively delete the block library since it has the tag - including your changes.

Hi Yannick, thanks for the review, i changed line 1 and line 3 and saved as new block.
Out of interest ,is there another way to use the chat id in the block from the marketplace, or will the block be updated sometime?

I don’t know yet - I felt it was enough without the chat ID for most people, if it appears many actually need the chat ID then it could be valuable to duplicate all the blocks to include a chat ID version.

I don’t mind if you post your version as “Telegram Actions (with Chat ID parameters)” or similar to the marketplace too.

Thank’s Yannick, I posted the modified version to the marketplace.

1 Like

Yannick, i just tryed to install my version from the marketplace and it is not working, there is always a message “Installation of add-on 131112 failed”. The Information of the addon says “Provisioned With Karaf”

I found out and it works.