0.1.2 • Published 4 years ago

keep-me-posted v0.1.2

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

keep-me-posted

Execute code on a web page, send yourself a telegram message.

Install

npm install keep-me-posted

Usage

Import the keepMePosted function from 'keep-me-posted' Available params:

  • URL (String) Webpage URL on which the callback will be executed.
  • callback (function(...args)) Function to execute on the Webpage. Should return a message or an object containing a 'message' property.
  • settings (Object - Optional) Settings for telegram bot usage.
  • ...args (any[] - Optional) Parameters for the callback function.

NOTE: The callback function is executed in the webpage scop and not in your application scop, you will be able to access the window object and the DOM but will not be able to access any of you variables. You can pass extra arguments and catch them as arguments in your callback function.

Examples

const keepMePosted = require('keep-me-posted');

const URL = "https://github.com";
const settings = {
  telegramBotToken: 'my-bot-api-token' // Get it from BotFather
  chatId: 123456 // Send a message to your bot, then getUpdates
};

// Returning a String
keepMePosted(URL, () => window.location.href, settings);
// This will return a Promise that will resolve with "https://github.com"
// The bot will send a message "https://github.com"

// Returning an Object
function exec(foo) {
  return {
    message: 'Hi...',
    a: foo.a + 10
  };
}
keepMePosted(URL, exec, settings, {a: 1});
// This will return a Promise that will resolve with the object:
// { message: 'Hi...', a: 11 }
// The bot will send a message "Hi..."

// Avoiding a message
// return any non string value that does not contain a "message" property
keepMePosted(URL, () => ({a: 1}), settings);
// This will return a Promise that will resolve with the object:
// { a: 1 }
// The bot will not send a message