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

telegram-webhook-js

Package Overview
Dependencies
Maintainers
0
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegram-webhook-js - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

31

main.js

@@ -254,2 +254,33 @@ // telegram-bot.js

}
async getImageFromUpdate(update) {
if (update.message && update.message.photo) {
// Extract the highest resolution photo
const photoArray = update.message.photo;
const fileId = photoArray[photoArray.length - 1].file_id;
// Get file path
const fileInfo = await this.getFile(fileId);
const filePath = fileInfo.file_path;
// Construct the download URL
const fileUrl = `https://api.telegram.org/file/bot${this.token}/${filePath}`;
return fileUrl; // Return the URL to download the image
} else {
console.error('No photo found in update.');
return null;
}
}
async getFile(fileId) {
try {
const response = await fetch(`${this.apiUrl}getFile?file_id=${fileId}`);
const data = await response.json();
return data.result;
} catch (error) {
console.error('Error getting file:', error);
}
}
}

2

package.json
{
"name": "telegram-webhook-js",
"version": "1.0.3",
"version": "1.0.4",
"main": "main.js",

@@ -5,0 +5,0 @@ "scripts": {

@@ -5,3 +5,3 @@ # Telegram Webhook JS

This library provides a simplified interface to interact with the Telegram Bot API, enabling you to create, manage, and operate a Telegram bot. It includes methods to send messages, edit messages, handle updates, send various types of media, and manage callback queries for inline buttons.
This library provides a simplified interface to interact with the Telegram Bot API, enabling you to create, manage, and operate a Telegram bot. It includes methods to send messages, edit messages, handle updates, send various types of media, manage callback queries for inline buttons, and handle menu button keyboards.

@@ -192,2 +192,51 @@ ## Installation

### Extracting an Image from Updates
To retrieve an image from an update, you can use the following method in your `TelegramBot` class:
```js
async getImageFromUpdate(update) {
if (update.message && update.message.photo) {
// Extract the highest resolution photo
const photoArray = update.message.photo;
const fileId = photoArray[photoArray.length - 1].file_id;
// Get file path
const fileInfo = await this.getFile(fileId);
const filePath = fileInfo.file_path;
// Construct the download URL
const fileUrl = `https://api.telegram.org/file/bot${this.token}/${filePath}`;
return fileUrl; // Return the URL to download the image
} else {
console.error('No photo found in update.');
return null;
}
}
async getFile(fileId) {
try {
const response = await fetch(`${this.apiUrl}getFile?file_id=${fileId}`);
const data = await response.json();
return data.result;
} catch (error) {
console.error('Error getting file:', error);
}
}
```
You can use this method to handle image updates in your bot:
```js
const updates = await bot.getUpdates();
for (const update of updates) {
const imageUrl = await bot.getImageFromUpdate(update);
if (imageUrl) {
console.log('Image URL:', imageUrl);
// You can now download the image or process it further
}
}
```
## API Reference

@@ -300,2 +349,2 @@

- `callbackData` (string): The callback data to handle.
- `handler` (function): The handler function to execute when the callback data is received.
- `handler` (function): The handler function to execute when the callback data is received.
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