I have a mass mailings system using the Telegram API written in javascript. This system uses a premium account and I want to use premium emoji in messages, but I can’t figure out how this works. Can anyone give me an example of code that uses premium emoji in a message? My message should contain a multiple emoji and text.
You can find the code for my mailing system below:
const { TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");
const fs = require("fs");
const path = require("path");
const input = require("input");
const apiId = 28107062;
const apiHash = "83933d5090483dd4733b1d25d3872737";
const sessionFilePath = path.join(__dirname, 'session.txt');
let stringSession = new StringSession("");
if (fs.existsSync(sessionFilePath)) {
stringSession = new StringSession(fs.readFileSync(sessionFilePath, 'utf-8'));
} else {
console.log("Session file not found. You will need to log in.");
}
const chatIds = [-1001966242541, -1001830585462, -1002118952351, -1002063174103, -1001389021288, -1001903976242, -1002342203094, -1002432255669, -1002423169211, -1002491856745, -1001252294905, 1002140505574, -1002367282121];
let messageCount = 0;
(async () => {
console.log("Loading interactive example...");
const client = new TelegramClient(stringSession, apiId, apiHash, {
connectionRetries: 5,
});
if (!fs.existsSync(sessionFilePath)) {
await client.start({
phoneNumber: async () => await input.text("Please enter your number: "),
password: async () => await input.text("Please enter your password: "),
phoneCode: async () => await input.text("Please enter the code you received: "),
onError: (err) => console.log(err),
});
fs.writeFileSync(sessionFilePath, client.session.save(), 'utf-8');
console.log("Session saved.");
} else {
await client.connect();
console.log("You should now be connected with the saved session.");
}
const filePath = path.join(__dirname, 'example.png');
const messagePath = path.join(__dirname, 'message.txt');
let messageText;
try {
messageText = fs.readFileSync(messagePath, 'utf-8');
} catch (error) {
console.error("Error reading message file:", error);
return;
}
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
const sendMessages = async () => {
for (const chatId of chatIds) {
try {
await client.sendFile(chatId, {
file: filePath,
caption: messageText,
});
messageCount++;
const now = new Date();
const formattedDate = now.toLocaleString();
console.log(`${formattedDate} - ${messageCount} message(s) sent to chat ID: ${chatId}`);
} catch (error) {
if (error.code === 403 && error.errorMessage === 'CHAT_SEND_PHOTOS_FORBIDDEN') {
console.log(`Cannot send photo to chat ID: ${chatId}, sending text instead.`);
try {
await client.sendMessage(chatId, { message: messageText });
console.log(`Text message sent to chat ID: ${chatId}`);
} catch (sendTextError) {
console.error(`Error while sending text message to chat ID: ${chatId}`, sendTextError);
}
} else if (error.code === 403 && error.errorMessage === 'CHAT_WRITE_FORBIDDEN') {
console.log(`Cannot send any message to chat ID: ${chatId}. Permission denied. Skipping...`);
} else if (error.code === 420 && error.errorMessage.startsWith('FLOOD')) {
const waitTime = error.seconds * 1000;
console.log(`FLOOD_WAIT: Need to wait ${error.seconds} seconds before sending the next message.`);
await delay(waitTime);
} else {
console.error(`Error while sending photo and message to chat ID: ${chatId}`, error);
}
}
await delay(10000);
}
};
sendMessages();
setInterval(sendMessages, 3600000);
})();
My message should contain a multiple emoji and text.
I found information about bots not being able to use premium emoji, but I don’t think this is related to the telegram api, and I see other people using premium emoji in their mailings.