├── .npmrc ├── .github └── dependabot.yml ├── package.json └── src └── index.js /.npmrc: -------------------------------------------------------------------------------- 1 | registry=https://npm.pkg.github.com/adaptive -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: npm 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "07:00" 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@adaptive/sendto", 3 | "version": "0.1.0", 4 | "description": "send messages to messaging platforms", 5 | "main": "src/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/adaptive/sendto.git" 12 | }, 13 | "keywords": [ 14 | "javascript", 15 | "telegram", 16 | "slack" 17 | ], 18 | "files": [], 19 | "author": "Hugo Romano", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/adaptive/sendto/issues" 23 | }, 24 | "homepage": "https://github.com/adaptive/sendto#readme" 25 | } 26 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Send message to Slack users or users 3 | * @param {(number|string[])} users - users receiving the message 4 | * @param {string} emoji_icon - emoji for message 5 | * @param {string} message - string containing the message to be sent 6 | * @param {string} token - token 7 | * @version 0.1.0 8 | */ 9 | 10 | const sendSlack = async (users, emoji_icon, message, token) => { 11 | const send = async (user, emoji_icon, message, token) => { 12 | await fetch(`https://hooks.slack.com/services/${token}`, { 13 | method: "POST", 14 | headers: { 15 | "Content-Type": "application/json", 16 | }, 17 | body: JSON.stringify({ 18 | username: user, 19 | text: message, 20 | emoji_icon: emoji_icon, 21 | }), 22 | }); 23 | }; 24 | 25 | if (Array.isArray(users)) { 26 | for (let user of users) { 27 | await send(user, emoji_icon, message, token); 28 | } 29 | } else { 30 | await send(users, emoji_icon, message, token); 31 | } 32 | return true; 33 | }; 34 | 35 | /** 36 | * Send message to Telegram users or users 37 | * @param {(number|string[])} users - users receiving the message 38 | * @param {string} message - string containing the message to be sent 39 | * @param {string} token - token 40 | * @version 0.1.0 41 | */ 42 | 43 | const sendTelegram = async (users, message, token) => { 44 | const send = async (user, message, token) => { 45 | await fetch(`https://api.telegram.org/bot${token}/sendMessage`, { 46 | method: "POST", 47 | headers: { 48 | "Content-Type": "application/json", 49 | }, 50 | body: JSON.stringify({ 51 | chat_id: user, 52 | text: message, 53 | }), 54 | }); 55 | return true; 56 | }; 57 | 58 | if (Array.isArray(users)) { 59 | for (let user of users) { 60 | await send(user, message, token); 61 | } 62 | } else { 63 | await send(users, message, token); 64 | } 65 | return true; 66 | }; 67 | 68 | module.exports = { 69 | sendSlack, 70 | sendTelegram, 71 | }; 72 | --------------------------------------------------------------------------------