GoogleChrome / related-website-sets

Apache License 2.0
394 stars 473 forks source link

Dana indonesia #367

Closed Anakalim12 closed 4 months ago

Anakalim12 commented 4 months ago

TechXploitz Try 'Wordpress'

Sitemap Disclaimer Privacy Home Categories About Contact More... Try RTL Mode Disclaimer: The tutorials in our blog are solely for educational purposes. They do not substitute professional advice or services. Home AdlinkFly Scripts How to Create a Telegram Bot For AdlinkFly How to create Adlinkfly Telegram Bot. Using Replit how to create Adlinkfly Telegram Bot. Adlinkfly script tlegram bot codes. How to make telegram bot. Estimated read time: 5 min Telegram Bot For AdlinkFly Script In this Article, I'll show you how to create a Telegram bot that can help improve the performance of your AdlinkFly script. Telematic bots are a great way to interact with your followers and automate tasks. They're a great way to add some extra value to your URL shortenng service. We'll go over everything you need to know, from setting up an account to integrating your Telegram bot with your AdlinkFly script. Lets get started.

How to Get Your Bot Token To create a new bot, you must first speak with BotFather. No, he's not a human; he's a bot who serves as a leader of all Telegram bots.

  1. Search for @botfather in Telegram.

BotFather Telegram Bot

  1. Start a conversation with BotFather by clicking on the Start button.

BotFather Bot

  1. Type /newbot, and follow the prompts to set up a new bot. The BotFather will give you a token that you will use to authenticate your bot and grant it access to the Telegram API.

AdlinkFly Bot

Make sure you store the token securely. Anyone with your token access can easily manipulate your bot.

How to Set Up Your AdlinkFly Bot Goto Replit and create an account.

Then create a new Repl. Select Node.js as Template and Give a suitable Title to your Repl.

Repl for AdlinkFly Telegram Bot

Now Paste the below Nodejs code to your Repl.

const TelegramBot = require('node-telegram-bot-api'); const axios = require('axios'); const fs = require('fs');

const express = require('express'); const app = express();

app.get('/', (req, res) => { res.send('Hello World!'); });

const port = 3000; app.listen(port, () => { console.log(Server running at http://localhost:${port}); });

// Retrieve the Telegram bot token from the environment variable const botToken = process.env.TELEGRAM_BOT_TOKEN;

// Create the Telegram bot instance const bot = new TelegramBot(botToken, { polling: true });

// Handle /start command bot.onText(/\/start/, (msg) => { const chatId = msg.chat.id; const username = msg.from.username; const welcomeMessage = Hello, ${username}!\n\n

// Command: /setarklinks bot.onText(/\/setarklinks (.+)/, (msg, match) => { const chatId = msg.chat.id; const userToken = match[1].trim(); // Get the API token provided by the user

// Save the user's MyBios API token to the database saveUserToken(chatId, userToken);

const response = MyBios API token set successfully. Your token: ${userToken}; bot.sendMessage(chatId, response); });

// Listen for any message (not just commands) bot.on('message', (msg) => { const chatId = msg.chat.id; const messageText = msg.text;

// If the message starts with "http://" or "https://", assume it's a URL and try to shorten it if (messageText && (messageText.startsWith('http://') || messageText.startsWith('https://'))) { shortenUrlAndSend(chatId, messageText); } });

// Function to shorten the URL and send the result async function shortenUrlAndSend(chatId, Url) { // Retrieve the user's MyBios API token from the database const arklinksToken = getUserToken(chatId);

if (!arklinksToken) { bot.sendMessage(chatId, 'Please provide your MyBios API token first. Use the command: /setarklinks YOUR_MYBIOS_API_TOKEN'); return; }

try { const apiUrl = https://your-adlinkfly-url/api?api=${arklinksToken}&url=${Url};

// Make a request to the MyBios API to shorten the URL
const response = await axios.get(apiUrl);
const shortUrl = response.data.shortenedUrl;

const responseMessage = `Shortened URL: ${shortUrl}`;
bot.sendMessage(chatId, responseMessage);

} catch (error) { console.error('Shorten URL Error:', error); bot.sendMessage(chatId, 'An error occurred while shortening the URL. Please check your API token and try again.'); } }

// Function to validate the URL format function isValidUrl(url) { const urlPattern = /^(|ftp|http|https):\/\/[^ "]+$/; return urlPattern.test(url); }

// Function to save user's MyBios API token to the database (Replit JSON database) function saveUserToken(chatId, token) { const dbData = getDatabaseData(); dbData[chatId] = token; fs.writeFileSync('database.json', JSON.stringify(dbData, null, 2)); }

// Function to retrieve user's MyBios API token from the database function getUserToken(chatId) { const dbData = getDatabaseData(); return dbData[chatId]; }

// Function to read the database file and parse the JSON data function getDatabaseData() { try { return JSON.parse(fs.readFileSync('database.json', 'utf8')); } catch (error) { // Return an empty object if the file doesn't exist or couldn't be parsed return {}; } }