Telegram Actions (with Chat ID parameters)

logo

This is the same block library as the original block library from Yannick, just with the chatID parameters added.

Blocks

Telegram1

Telegram2

Changelog

Version 0.1

  • initial release

Resources




uid: telegram_with_chatID
tags: []
props:
  parameters: []
  parameterGroups: []
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:
          - align: right
            name: ATTACHMENT_TYPE
            options:
              - - photo
                - Photo
              - - animation
                - Animation
              - - video
                - Video
            type: field_dropdown
          - align: right
            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
        colour: "#2ea5d8"
        helpUrl: ""
        inputsInline: false
        lastDummyAlign0: right
        lastDummyAlignRight0: true
        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:
          - align: right
            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
        colour: "#2ea5d8"
        helpUrl: ""
        inputsInline: false
        lastDummyAlign0: right
        lastDummyAlignRight0: true
        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:
          - align: right
            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
        colour: "#2ea5d8"
        helpUrl: ""
        inputsInline: false
        lastDummyAlign0: right
        lastDummyAlignRight0: true
        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:
          - align: right
            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
        colour: "#2ea5d8"
        helpUrl: ""
        inputsInline: false
        lastDummyAlign0: right
        lastDummyAlign1: right
        lastDummyAlignRight0: true
        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
5 Likes

Do you want to include the chat id’s in the existing telegram library at some point?
I think it doesn’t make sense to maintain two of them in parallel.

That would make sense, the existing library is from @ysc, if he agree with it i will remove mine.

Would totally make sense, since one would have to add several things otherwise for different chats.
And from what i have seen in the logs, the binding complains with some warnings when different things/bots with the same api key are online in parallel.

Maybe the blocks could use the chat id as an optional parameter at a later point and send to all configured chat ids when none is specified.

Can somebody explain how to send a picture from an item? Are only file and url working?

the picture is contained in the item and should be sent or would you like to use the item to trigger a picture to be sent ?

Yes, its an item picture. I want to send the picture from and item. The picture is a data jpeg base64 encoded.
grafik

The telegram doc contains the following example:

rule "Send telegram with Image Item image and caption"
when
    Item Webcam_Image changed
then
    val telegramAction = getActions("telegram","telegram:telegramBot:2b155b22")
    telegramAction.sendTelegramPhoto(Webcam_Image.state.toFullString, "sent from openHAB")
end

So you should be able get the data content of your item in the required format by using YourItem.state.toFullString

How can I do this with Blockly?

sorry, that I do not know. I am not experienced with Blockly.

According to the docu Rules Blockly - Items & Things | openHAB you may try to assign the item state to a variable and then force the string conversion. I am not sure if that will work.

In case that is already what you showed in your previous screenshot then try to cut off everything before the comma ( data…base64, ) the remaining part should be the base64 encoded picture.

Thanks for your help, but that won’t work. This thread handle blockly and everything else don’t help me really. I tried out what you think but that don’t work.

I send out some infos:

And when i try this:

grafik

Get this:

In your post ( #7 ) you showed a screenshot of base64 encoded string that starts with data:image/jpeg;base64,, Did you print this from within blockly or how do you know that this is the content of your picture item ? Or was it even taken from a different context ?

Thats a mistake from me. I open the picture in a new tab of the browser and i get base64 code. Sorry for that.
What you see is the info from the blockly.