Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remotepn

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remotepn - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

cli.ts

241

dist/index.js

@@ -1,73 +0,76 @@

#!/usr/bin/env node
(() => {
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// ../node_modules/node-fetch/browser.js
var require_browser = __commonJS({
"../node_modules/node-fetch/browser.js"(exports, module) {
"use strict";
var getGlobal = function() {
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw new Error("unable to locate global object");
};
var globalObject = getGlobal();
module.exports = exports = globalObject.fetch;
if (globalObject.fetch) {
exports.default = globalObject.fetch.bind(globalObject);
}
exports.Headers = globalObject.Headers;
exports.Request = globalObject.Request;
exports.Response = globalObject.Response;
}
});
// index.ts
var remote_prompt_notification_exports = {};
__export(remote_prompt_notification_exports, {
default: () => RemotePN
});
module.exports = __toCommonJS(remote_prompt_notification_exports);
// index.ts
var import_node_fetch = __toESM(require_browser());
var postRequest = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
// shared.ts
var import_node_fetch = __toESM(require("node-fetch"), 1);
var postRequest = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
}
};
var sendMessage = async (token, username, message) => {
const response = await (0, import_node_fetch.default)(
"https://api.telegram.org/bot" + token + "/sendMessage",
{
...postRequest,
body: JSON.stringify({
chat_id: username,
text: message
})
}
);
const jsonResponse = await response.json();
if (!jsonResponse.ok) {
console.error("Error while sending: ", jsonResponse);
process.exit(1);
}
return {
messageId: jsonResponse.result.message_id
};
var sendMessage = async (token, username, message) => {
};
var awaitReply = async (token, userId, messageId) => {
let offset = 0;
while (true) {
const response = await (0, import_node_fetch.default)(
"https://api.telegram.org/bot" + token + "/sendMessage",
"https://api.telegram.org/bot" + token + "/getUpdates",
{
...postRequest,
body: JSON.stringify({
chat_id: username,
text: message
offset,
timeout: 25,
allowed_updates: ["message", "message_reaction", "poll_answer"]
})

@@ -77,77 +80,45 @@ }

const jsonResponse = await response.json();
if (!jsonResponse.ok) {
console.error("Error while sending: ", jsonResponse);
process.exit(1);
}
return {
messageId: jsonResponse.result.message_id
};
};
var awaitReply = async (token, userId, messageId) => {
let offset = 0;
while (true) {
const response = await (0, import_node_fetch.default)(
"https://api.telegram.org/bot" + token + "/getUpdates",
{
...postRequest,
body: JSON.stringify({
offset,
timeout: 25,
allowed_updates: ["message", "message_reaction", "poll_answer"]
})
}
if (jsonResponse.ok) {
const found = jsonResponse.result.find(
(res) => res.message && res.message.from.id == userId && res.message.chat.id == userId && res.message.reply_to_message && res.message.reply_to_message.message_id === messageId || res.message_reaction && res.message_reaction.chat.id == userId && res.message_reaction.user.id == userId && res.message_reaction.message_id == messageId
);
const jsonResponse = await response.json();
if (jsonResponse.ok) {
const found = jsonResponse.result.find(
(res) => res.message && res.message.from.id == userId && res.message.chat.id == userId && res.message.reply_to_message && res.message.reply_to_message.message_id === messageId || res.message_reaction && res.message_reaction.chat.id == userId && res.message_reaction.user.id == userId && res.message_reaction.message_id == messageId
);
if (found && found.message) {
return found.message.text;
} else if (found && found.message_reaction) {
if (found.message_reaction.new_reaction.find((x) => x.emoji == "\u{1F44D}")) {
return "Y";
} else if (found.message_reaction.new_reaction.find((x) => x.emoji == "\u{1F44E}")) {
return "N";
}
} else if (jsonResponse.length >= 100) {
offset = jsonResponse.result.slice(-1).update_id;
if (found && found.message) {
return found.message.text;
} else if (found && found.message_reaction) {
if (found.message_reaction.new_reaction.find((x) => x.emoji == "\u{1F44D}")) {
return "Y";
} else if (found.message_reaction.new_reaction.find((x) => x.emoji == "\u{1F44E}")) {
return "N";
}
} else if (jsonResponse.length >= 100) {
offset = jsonResponse.result.slice(-1).update_id;
}
await new Promise((resolve) => setTimeout(resolve, 5e3));
}
};
var parseArgs = () => {
const args = process.argv.slice(2);
const telegramTokenArg = args.find((x) => x.match(/\-\-telegramToken\=/));
if (!telegramTokenArg) {
console.log("Missing --telegramToken param");
process.exit(1);
}
const telegramUserArg = args.find(
(x) => x.match(/\-\-telegramUser\=[0-9]{7,10}/)
await new Promise((resolve) => setTimeout(resolve, 5e3));
}
};
// index.ts
var RemotePN = class {
telegramToken;
telegramUser;
constructor({
telegramToken,
telegramUser
}) {
}
async prompt(message) {
const { messageId } = await sendMessage(
this.telegramToken,
this.telegramUser,
message
);
if (!telegramUserArg) {
console.log("Missing or wrong --telegramUser param");
process.exit(1);
}
const messageArg = args.find((x) => x.match(/\-\-message\=/));
if (!messageArg) {
console.log("Missing --message param");
process.exit(1);
}
return {
telegramToken: telegramTokenArg.replace("--telegramToken=", ""),
telegramUser: telegramUserArg.replace("--telegramUser=", ""),
message: messageArg.replace("--message=", "")
};
};
var start = async () => {
const { telegramToken, telegramUser, message } = parseArgs();
const { messageId } = await sendMessage(telegramToken, telegramUser, message);
const response = await awaitReply(telegramToken, telegramUser, messageId);
process.stdout.write(response);
process.exit(0);
};
start();
})();
const response = await awaitReply(
this.telegramToken,
this.telegramUser,
messageId
);
return response;
}
};
//# sourceMappingURL=index.js.map

@@ -1,124 +0,27 @@

#!/usr/bin/env node
import { awaitReply, sendMessage } from "./shared";
import fetch from "node-fetch";
export default class RemotePN {
telegramToken: string;
telegramUser: string;
const postRequest = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
};
const sendMessage = async (
token: string,
username: string,
message: string
) => {
const response = await fetch(
"https://api.telegram.org/bot" + token + "/sendMessage",
{
...postRequest,
body: JSON.stringify({
chat_id: username,
text: message,
}),
}
);
const jsonResponse = await response.json();
if (!jsonResponse.ok) {
console.error("Error while sending: ", jsonResponse);
process.exit(1);
}
return {
messageId: jsonResponse.result.message_id,
};
};
const awaitReply = async (token: string, userId: string, messageId: number) => {
let offset = 0;
while (true) {
const response = await fetch(
"https://api.telegram.org/bot" + token + "/getUpdates",
{
...postRequest,
body: JSON.stringify({
offset,
timeout: 25,
allowed_updates: ["message", "message_reaction", "poll_answer"],
}),
}
constructor({
telegramToken,
telegramUser,
}: {
telegramToken: string;
telegramUser: string;
}) {}
async prompt(message: string) {
const { messageId } = await sendMessage(
this.telegramToken,
this.telegramUser,
message
);
const jsonResponse = await response.json();
if (jsonResponse.ok) {
const found = jsonResponse.result.find(
(res: any) =>
(res.message &&
res.message.from.id == userId &&
res.message.chat.id == userId &&
res.message.reply_to_message &&
res.message.reply_to_message.message_id === messageId) ||
(res.message_reaction &&
res.message_reaction.chat.id == userId &&
res.message_reaction.user.id == userId &&
res.message_reaction.message_id == messageId)
);
if (found && found.message) {
return found.message.text;
} else if (found && found.message_reaction) {
if (
found.message_reaction.new_reaction.find((x: any) => x.emoji == "👍")
) {
return "Y";
} else if (
found.message_reaction.new_reaction.find((x: any) => x.emoji == "👎")
) {
return "N";
}
} else if (jsonResponse.length >= 100) {
offset = jsonResponse.result.slice(-1).update_id;
}
}
await new Promise((resolve) => setTimeout(resolve, 5000));
const response = await awaitReply(
this.telegramToken,
this.telegramUser,
messageId
);
return response;
}
};
const parseArgs = () => {
const args = process.argv.slice(2);
const telegramTokenArg = args.find((x) => x.match(/\-\-telegramToken\=/));
if (!telegramTokenArg) {
console.log("Missing --telegramToken param");
process.exit(1);
}
const telegramUserArg = args.find((x) =>
x.match(/\-\-telegramUser\=[0-9]{7,10}/)
);
if (!telegramUserArg) {
console.log("Missing or wrong --telegramUser param");
process.exit(1);
}
const messageArg = args.find((x) => x.match(/\-\-message\=/));
if (!messageArg) {
console.log("Missing --message param");
process.exit(1);
}
return {
telegramToken: telegramTokenArg.replace("--telegramToken=", ""),
telegramUser: telegramUserArg.replace("--telegramUser=", ""),
message: messageArg.replace("--message=", ""),
};
};
const start = async () => {
const { telegramToken, telegramUser, message } = parseArgs();
const { messageId } = await sendMessage(telegramToken, telegramUser, message);
const response = await awaitReply(telegramToken, telegramUser, messageId);
process.stdout.write(response);
process.exit(0);
};
start();
}
{
"name": "remotepn",
"version": "1.0.2",
"version": "1.0.3",
"description": "",
"main": "./dist/index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "esbuild index.ts --bundle --outfile=./dist/index.js"
"build-cli": "esbuild cli.ts --bundle --outfile=./dist/cli.js --platform=node --target=node14 --external:node-fetch",
"build": "npm run build-cli && npm run build-lib",
"build-lib": "esbuild index.ts --bundle --outfile=./dist/index.js --sourcemap --platform=node --target=node14 --external:node-fetch"
},
"bin": {
"remotepn": "./dist/index.js"
"remotepn": "./dist/cli.js"
},
"exports": {
"default": "./dist/index.js"
},
"author": "",

@@ -14,0 +20,0 @@ "license": "ISC",

@@ -13,17 +13,25 @@ # Remote Prompt Notification

Create a BOT with bothfather and take note of the TOKEN
1. Create a BOT with bothfather and take note of the TOKEN
Get your user ID in telegram by adding the bot @userinfobot you will receive your user id number (eg. 101111333)
2. Get your user ID in telegram by adding the bot @userinfobot you will receive your user id number (eg. 101111333)
## Bash / Shell
npx remotepn prompt --telegramToken=6953209111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA --telegramUser=101111333 --message="How are you?"
```bash
npx remotepn --telegramToken=6953209111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA --telegramUser=101111333 --message="How are you?"
```
## Javascript / Typescript
```typescript
import RemotePN from "remotepn";
const client = new RemotePN({
telegramToken: "6953209111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
telegramUser: 101111333
})
telegramToken: "6953209111:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
telegramUser: 101111333,
});
const answer = await client.prompt("Hello World");
```
## Answering
You can either answer the message by long pressing the message and "Answer" or use a reaction
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc