node-telegram-gateway-api
v1.2.1
Published
A Node.js package to interact with the Telegram Gateway API for sending verification messages and checking verification status.
Downloads
70
Maintainers
Readme
📲 Telegram Gateway API Client
A Node.js client for interacting with the Telegram Gateway API to manage phone verification messages easily. This library simplifies sending verification messages, checking their status, and revoking them.
📦 Installation
Install the package using npm:
npm install node-telegram-gateway-api
🚀 Getting Started
First, you need to obtain your API key from the Telegram Gateway API account settings. This key will be used to authorize all requests.
import { TelegramGateway } from "node-telegram-gateway-api";
const apiKey = "YOUR_TELEGRAM_API_KEY";
const client = new TelegramGateway(apiKey);
📚 Usage Guide
1. Send a Verification Message
Use sendVerificationMessage
to send a verification code to a specified phone number:
async function sendVerification() {
try {
const response = await client.sendVerificationMessage("+1234567890", {
sender_username: "YourApp",
code_length: 6,
});
if (response.ok) {
console.log("Message sent successfully:", response.result);
} else {
console.error("Error sending message:", response.error);
}
} catch (error) {
console.error("API request failed:", error);
}
}
2. Check Send Ability
Before sending a message, you can verify if it is possible to send a message to the given phone number:
async function checkSendAbility() {
try {
const response = await client.checkSendAbility("+1234567890");
if (response.ok) {
console.log("Able to send verification message:", response.result);
} else {
console.error("Cannot send message:", response.error);
}
} catch (error) {
console.error("API request failed:", error);
}
}
3. Check Verification Status
After sending a verification message, you can check its status:
async function checkVerificationStatus() {
try {
const response = await client.checkVerificationStatus(
"request_id_here",
"user_entered_code"
);
if (response.ok) {
console.log("Verification status:", response.result);
} else {
console.error("Error checking status:", response.error);
}
} catch (error) {
console.error("API request failed:", error);
}
}
4. Revoke a Verification Message
If needed, you can revoke a verification message that was previously sent:
async function revokeMessage() {
try {
const response = await client.revokeVerificationMessage("request_id_here");
if (response.ok) {
console.log("Message revoked successfully");
} else {
console.error("Error revoking message:", response.error);
}
} catch (error) {
console.error("API request failed:", error);
}
}
📖 Documentation
For more detailed information about the Telegram Gateway API, visit the official documentation.
🛠️ Contributing
Feel free to submit issues or contribute to the project through pull requests. Contributions are welcome! 🙌
📝 License
This project is licensed under the MIT License.