LukeSkywalker92/TeleFrame

[feature request] friendly reminder

call-me-matt opened this issue · 5 comments

I would like the teleframe to remind me with a short telegram message if there have been no new photos for more than two weeks.

Probably this could be an addon simply resetting a timer on newImage listener - but a sendTelegramMsg input event would be needed.

gegu commented

It should be possible to implement the required function in the addon.

You need a listener for the event teleFrame-ready. There you can save a reference to the telegram object of the bot for further use.

const function sendImageReminder = (interface) => {
	const telegram = null;

	interface.registerListener('teleFrame-ready', teleFrameObjects => {
	  telegram = teleFrameObjects.bot.telegram;
	});

}

So, here we go!
https://github.com/call-me-matt/teleframe-imageReminder

  • Could you help me with l10n for the message?
  • And not sure how to handle wrong whitelist-entries. I get this error:
(node:88671) UnhandledPromiseRejectionWarning: Error: 400: Bad Request: chat not found
    at node_modules/telegraf/core/network/client.js:281:17
    at processTicksAndRejections (internal/process/task_queues.js:85:5)
(node:88671) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:88671) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
gegu commented

Unfortunately it is not possible to determine the language of a chatid.
So you have to implement the handling yourself. For example you could use a standard message and optionally define the message to be sent in the config section of your addon for a specific chatid.

To handle the promise rejection implement a catch handler - see example code below.

Define messages for specific chatid's inconfig.json:

{

  "addonInterface": {
    "addons": {
      "imageReminder": {
        "enabled": true,
          "reminderMessage": {
            "chatid-1":"Message for chatid-1",
            "chatid-2":"Message for chatid-2"
          }
        }
     }
  }
}

Example code (untested)

for (i in config.whitelistChats) {
  let reminderMsg = "hey hey, please feed me with new photos 🤖";
  try {
    reminderMsg = interface.config.reminderMessage[config.whitelistChats[i]] || reminderMsg;
  } catch(_) {}

  // send message and catch errors
  telegram.sendMessage(config.whitelistChats[i], reminderMsg)
  .catch(error => {
    interface.logger.error(error);
  });
}

Ah, I see. Thank you for your instant reply! The catch for telegram was exactly what I was looking for.
Concerning the translation of the reminder, it's maybe a little too much, then. So I will introduce just one constant here.

I have added this to the wiki. Took over the name you chose (imageReminder). Thank you @gegu !