0% found this document useful (0 votes)
7 views4 pages

TG Bot

The document outlines a Telegram bot configuration that automatically accepts new members in a group and sends them a welcome message. It includes code snippets for setting up the bot, handling join requests, and sending messages to users. The bot is designed to promote new members and provide a private welcome message upon their joining the channel.

Uploaded by

romansp92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

TG Bot

The document outlines a Telegram bot configuration that automatically accepts new members in a group and sends them a welcome message. It includes code snippets for setting up the bot, handling join requests, and sending messages to users. The bot is designed to promote new members and provide a private welcome message upon their joining the channel.

Uploaded by

romansp92
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

7074240731:AAEgyGHr0EizEcP1f038N8VmBPYYPtcioW0

27802520

6fbac534055e59afa8e6c804969f1e35

{
"ok": true,
"result": {
"id": 7074240731,
"is_bot": true,
"first_name": "Auto Request Accept Bot",
"username": "google_imgbot",
"can_join_groups": true,
"can_read_all_group_messages": false,
"supports_inline_queries": false,
"can_connect_to_business": false
}
}

web url ;
https://script.google.com/macros/s/
AKfycbw3vrznJ7PanZW3CWfCdc0Msx35VIeYRNRi8nynZuSoyMZPyJUK2Fuh0_vlTBKDNGtGcw/exec

deploy id;
AKfycbw3vrznJ7PanZW3CWfCdc0Msx35VIeYRNRi8nynZuSoyMZPyJUK2Fuh0_vlTBKDNGtGcw

let token = "7074240731:AAEgyGHr0EizEcP1f038N8VmBPYYPtcioW0";


var command = {
"/start": "Welcome"
}

function getme() {
let response = UrlFetchApp.fetch("https://api.telegram.org/bot" + token +
"/getMe");
console.log(response.getContentText());
}

function setWebhook(){
let webAppUrl =
"https://script.google.com/macros/s/AKfycbw3vrznJ7PanZW3CWfCdc0Msx35VIeYRNRi8nynZuS
oyMZPyJUK2Fuh0_vlTBKDNGtGcw/exec";
let response = UrlFetchApp.fetch("https://api.telegram.org/bot" + token +
"/setWebhook?url="+webAppUrl);
console.log(response.getContentText());
}

function doPost(e) {
var payload = JSON.parse(e.postData.contents);
// Check if this is a new member joining the group/channel
if (payload.message && payload.message.new_chat_member) {
var newMember = payload.message.new_chat_member;
var chatId = payload.message.chat.id;
var chatTitle = payload.message.chat.title;

// Automatically accept the new member


var response = acceptNewMember(chatId, newMember.id);

// Send a welcome message


var welcomeMessage = `Hey ${chatTitle}! I've been added to your group/channel.
To accept join requests automatically, add me as an admin.`;
sendMessage(chatId, welcomeMessage);

// Return a success response to Telegram


return ContentService.createTextOutput(JSON.stringify(response));
}

// Handle other types of updates as needed

return ContentService.createTextOutput("OK");
}

function acceptNewMember(chatId, userId) {


var url =
'https://api.telegram.org/bot7074240731:AAEgyGHr0EizEcP1f038N8VmBPYYPtcioW0/
promoteChatMember';

var payload = {
'chat_id': chatId,
'user_id': userId,
'can_change_info': true,
'can_post_messages': true,
'can_edit_messages': true,
'can_delete_messages': true,
'can_invite_users': true,
'can_restrict_members': true,
'can_pin_messages': true,
'can_promote_members': true
};

var options = {
'method' : 'post',
'payload' : JSON.stringify(payload),
'contentType': 'application/json',
'muteHttpExceptions': true
};

var response = UrlFetchApp.fetch(url, options);


return JSON.parse(response.getContentText());
}

function sendMessage(chatId, text) {


var url =
'https://api.telegram.org/bot7074240731:AAEgyGHr0EizEcP1f038N8VmBPYYPtcioW0/
sendMessage';

var payload = {
'chat_id': chatId,
'text': text
};

var options = {
'method' : 'post',
'payload' : JSON.stringify(payload),
'contentType': 'application/json',
'muteHttpExceptions': true
};

var response = UrlFetchApp.fetch(url, options);


return JSON.parse(response.getContentText());
}

start / hey shivam add a snippet which is when a user joines a telegram channel
via bot send a privet messgage to user ilke hey user you have joined this telegram
channe

import asyncio
from telegram import Bot
from telegram.error import TelegramError
# Replace with your actual bot token
BOT_TOKEN = '7074240731:AAEgyGHr0EizEcP1f038N8VmBPYYPtcioW0'

async def approve_join_requests(bot):


offset = 0
while True:
try:
updates = await bot.get_updates(offset=offset, timeout=30)
for update in updates:
offset = update.update_id + 1

if update.chat_join_request:
chat_id = update.chat_join_request.chat.id
user_id = update.chat_join_request.from_user.id

try:
await bot.approve_chat_join_request(chat_id=chat_id,
user_id=user_id)
print(f"Approved join request for user {user_id} in chat
{chat_id}")

# Send a private message to the user


channel_name = update.chat_join_request.chat.title
await bot.send_message(chat_id=user_id, text=f"Hey
{update.chat_join_request.from_user.first_name}, Your request to join the channel
'{channel_name}' has been approved.")
print(f"Sent welcome message to user {user_id}")
except TelegramError as e:
print(f"Failed to approve join request for user {user_id}
in chat {chat_id}: {e}")
if e.message == "Hide_requester_missing":
print(f"User information hidden for join request in
chat {chat_id}. Skipping.")
elif e.message == "User_already_participant":
print(f"User {user_id} is already a participant in chat
{chat_id}.")
else:
print(f"Unhandled error: {e}")
# Log the full error details for debugging
print(f"Error details: {e.__dict__}")

except TelegramError as e:
print(f"Error getting updates: {e}")
await asyncio.sleep(5)

async def main():


bot = Bot(token=BOT_TOKEN)
await approve_join_requests(bot)

if __name__ == '__main__':
asyncio.run(main())

You might also like