# Telegram giving me to messages

**URL:** https://discourse.nodered.org/t/telegram-giving-me-to-messages/73233
**Category:** General
**Created:** [5 January 2023 15:37 UTC](https://discourse.nodered.org/t/telegram-giving-me-to-messages/73233 "2023-01-05T15:37:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![tpbillund](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tpbillund/32/37410_2.png) [@tpbillund](https://discourse.nodered.org/u/tpbillund)
#### Post date: [5 January 2023 15:37 UTC](https://discourse.nodered.org/t/telegram-giving-me-to-messages/73233/1 "2023-01-05T15:37:55Z")

</div>

Hi.  
I have this flow, that control a folder in my mail, and if there is a mail it grab the image and send it by telegram, and then delete the message.  
My problem is, that I get two telegram messages, with the same image of all mails in the folder.

So every mail, is send by telegram two times before going to the next mail.  
How can I edit the flow, so I only will get one telegram message, when getting a mail?

```auto
[
    {
        "id": "c0a3796d552b0784",
        "type": "comment",
        "z": "b76b4fef47b27005",
        "name": "Telegram besked, ved Motion Detection!",
        "info": "Benytter:\nnode-red-contrib-watchdirectory\nnode-red-contrib-telegrambot\n###############################\n1 x Watch-directory node (Watchdirectory)\n1 x Switch node (NR)\n1 x Function node (NR)\n1 x Delay node (NR)\n1 x Sender node (Telegram)\n3 x Debug node (NR)",
        "x": 170,
        "y": 460,
        "wires": []
    },
    {
        "id": "7e395e24d3d47c87",
        "type": "inject",
        "z": "b76b4fef47b27005",
        "name": "Search every 5. sec",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "deletepath",
                "v": "\\NVR",
                "vt": "str"
            }
        ],
        "repeat": "10",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 160,
        "y": 540,
        "wires": [
            [
                "a258fa9580855fe3"
            ]
        ]
    },
    {
        "id": "fbbd4cae89642a30",
        "type": "debug",
        "z": "b76b4fef47b27005",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "topic",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 980,
        "y": 620,
        "wires": []
    },
    {
        "id": "152df24f339b5417",
        "type": "split",
        "z": "b76b4fef47b27005",
        "name": "",
        "splt": "\\n",
        "spltType": "str",
        "arraySplt": 1,
        "arraySpltType": "len",
        "stream": false,
        "addname": "",
        "x": 810,
        "y": 540,
        "wires": [
            [
                "d6429274201ec237"
            ]
        ]
    },
    {
        "id": "52ed7dd302baaf28",
        "type": "change",
        "z": "b76b4fef47b27005",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "attachments",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 640,
        "y": 540,
        "wires": [
            [
                "152df24f339b5417"
            ]
        ]
    },
    {
        "id": "2a8cc13f57e5f3c3",
        "type": "telegram sender",
        "z": "b76b4fef47b27005",
        "name": "",
        "bot": "",
        "haserroroutput": false,
        "outputs": 1,
        "x": 410,
        "y": 640,
        "wires": [
            [
                "9202bd61346071f2"
            ]
        ]
    },
    {
        "id": "d6429274201ec237",
        "type": "change",
        "z": "b76b4fef47b27005",
        "name": "compose filename and load content to payload",
        "rules": [
            {
                "t": "set",
                "p": "filename",
                "pt": "msg",
                "to": "\"/NVR/snap\" & $millis() & \".jpg\"",
                "tot": "jsonata"
            },
            {
                "t": "set",
                "p": "payload",
                "pt": "msg",
                "to": "payload.content",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1080,
        "y": 540,
        "wires": [
            [
                "26ac0911f6568cd9",
                "fbbd4cae89642a30",
                "715a7f87f2c0a4d3"
            ]
        ]
    },
    {
        "id": "26ac0911f6568cd9",
        "type": "file",
        "z": "b76b4fef47b27005",
        "name": "Save picture to disk",
        "filename": "filename",
        "filenameType": "msg",
        "appendNewline": true,
        "createDir": true,
        "overwriteFile": "true",
        "encoding": "none",
        "x": 1070,
        "y": 480,
        "wires": [
            []
        ]
    },
    {
        "id": "715a7f87f2c0a4d3",
        "type": "function",
        "z": "b76b4fef47b27005",
        "name": "Set topic and filename",
        "func": "var payload = { \n chatId: -xxxxxxxxxxxxxxxx,\n type: \"photo\",\n content: msg.payload,\n caption: msg.topic + \"\\r\\nMotion detection fanget én eller flere personer\"};\n \nreturn {payload};",
        "outputs": 1,
        "noerr": 1,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 180,
        "y": 640,
        "wires": [
            [
                "2a8cc13f57e5f3c3"
            ]
        ]
    },
    {
        "id": "24d2922b1166c40e",
        "type": "comment",
        "z": "b76b4fef47b27005",
        "name": "Hent mail hver 5. sek., gem billede og slet mail!",
        "info": "Benytter:\nnode-red-contrib-watchdirectory\nnode-red-contrib-telegrambot\n###############################\n1 x Watch-directory node (Watchdirectory)\n1 x Switch node (NR)\n1 x Function node (NR)\n1 x Delay node (NR)\n1 x Sender node (Telegram)\n3 x Debug node (NR)",
        "x": 240,
        "y": 500,
        "wires": []
    },
    {
        "id": "23a9fc0a8bcf51b4",
        "type": "comment",
        "z": "b76b4fef47b27005",
        "name": "Send billede til Telegram, slet billede igen!",
        "info": "Benytter:\nnode-red-contrib-watchdirectory\nnode-red-contrib-telegrambot\n###############################\n1 x Watch-directory node (Watchdirectory)\n1 x Switch node (NR)\n1 x Function node (NR)\n1 x Delay node (NR)\n1 x Sender node (Telegram)\n3 x Debug node (NR)",
        "x": 220,
        "y": 600,
        "wires": []
    },
    {
        "id": "09f240891eecfc06",
        "type": "inject",
        "z": "b76b4fef47b27005",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 510,
        "y": 480,
        "wires": [
            [
                "a258fa9580855fe3"
            ]
        ]
    },
    {
        "id": "f550e83400270695",
        "type": "debug",
        "z": "b76b4fef47b27005",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 760,
        "y": 480,
        "wires": []
    },
    {
        "id": "a258fa9580855fe3",
        "type": "e-mail in",
        "z": "b76b4fef47b27005",
        "name": "Simply GET-Mail",
        "protocol": "IMAP",
        "server": "mail.simply.com",
        "useSSL": true,
        "autotls": "always",
        "port": "993",
        "box": "NVR",
        "disposition": "Delete",
        "criteria": "ALL",
        "repeat": "5",
        "fetch": "trigger",
        "inputs": 1,
        "x": 400,
        "y": 540,
        "wires": [
            [
                "f550e83400270695",
                "52ed7dd302baaf28"
            ]
        ]
    },
    {
        "id": "9202bd61346071f2",
        "type": "debug",
        "z": "b76b4fef47b27005",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "topic",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 620,
        "y": 620,
        "wires": []
    }
]

```

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [5 January 2023 18:07 UTC](https://discourse.nodered.org/t/telegram-giving-me-to-messages/73233/2 "2023-01-05T18:07:10Z")

</div>

Add a `debug` node (set to display the complete msg object) to the output of your `split` node and run your floe.

What do you see? Then ask yourself 'Why do I see this?"

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [6 March 2023 18:07 UTC](https://discourse.nodered.org/t/telegram-giving-me-to-messages/73233/3 "2023-03-06T18:07:21Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
