Skip to main content

CTS-Send alerts to gmail, Telegram

 Of course. Sending notifications from a Google Sheet to Telegram is an excellent and very popular alternative, especially since it doesn't have the same kind of administrator restrictions that Google Chat sometimes does.

You will need to use a "Telegram Bot." This isn't a complex program; it's just an automated Telegram account that your Google Apps Script can send messages to. The bot will then post those messages into your desired group or channel.

The process involves three main parts:

  1. Create a Telegram Bot and get its API Token.

  2. Get the Chat ID of the group or person you want to send messages to.

  3. Update your Google Apps Script to send the notification to Telegram's API.

Here is a full step-by-step guide.


Step 1: Create Your Telegram Bot and Get the API Token

You will use a special bot called "BotFather" to create your own bot.

  1. Open Telegram (on your phone or desktop app).

  2. In the search bar, type BotFather and select the official one with the blue checkmark.

  3. Start a chat with BotFather and send the command: /newbot

  4. BotFather will ask you for a name for your bot (e.g., "My Sheet Notifier").

  5. Then, it will ask for a username for your bot. This must be unique and end in bot (e.g., MySheetNotifier_bot).

  6. If successful, BotFather will give you a message containing your API Token. It will look something like 1234567890:ABCDEFGHIJKLMNOPQRSTUVWXYZ-abcdefgh.

Important: Treat this API Token like a password. Do not share it publicly. Copy it and save it somewhere safe for the next steps.

Step 2: Get Your Telegram Chat ID

The Chat ID tells your bot where to send the message.

A) For a Private Chat (to yourself):

  1. Search for a bot called @userinfobot in Telegram and start a chat.

  2. It will immediately reply with your Chat ID. It's usually a 9 or 10-digit number.

B) For a Group Chat:

  1. First, you must add your new bot (the one you created in Step 1) to the Telegram group.

  2. Then, add @userinfobot to the group. It will post a message with the group's Chat ID. The group Chat ID is a negative number (e.g., -100123456789).

  3. You can remove @userinfobot from the group after you have the ID.

Step 3: Update Your Google Apps Script

Now you will modify your script to send the data to the Telegram API instead of Google Chat.

  1. Open your Google Sheet and go to Extensions > Apps Script.

  2. Replace your existing code with the code below.

  3. Paste your Bot API Token and your Chat ID into the specified placeholders.

JavaScript
      // This is the function that runs every time you edit the sheet
function onEdit(e) {
  var range = e.range;
  var sheet = range.getSheet();
  
  // 1. Check if the edit was in the correct cell and sheet
  if (range.getA1Notation() === 'B64' && sheet.getName() === 'Dashboard') {
    var value = range.getValue();
    
    // 2. Check if the value contains the trigger words
    if (value.includes("Long Entry") || value.includes("Short Entry")) {
      var c60Value = sheet.getRange('C60').getValue();
      
      // --- Send Notification to Telegram ---
      sendTelegramNotification(c60Value);
      
      // --- Email Notification (Optional) ---
      // You can keep this or delete it if you only want Telegram alerts
      var emailRecipient = "your.email@gmail.com"; // Replace with your email
      var emailSubject = "Trading Signal Alert from Dashboard (B64)";
      var emailBody = c60Value + "\n\nGenerated on: " + new Date().toLocaleString();
      MailApp.sendEmail(emailRecipient, emailSubject, emailBody);
    }
  }
}

// This is the dedicated function to send the message to Telegram
function sendTelegramNotification(message) {
  
  // REPLACE these two variables with your own details from Step 1 and 2
  var botToken = "YOUR_TELEGRAM_BOT_TOKEN"; 
  var chatId = "YOUR_CHAT_ID";

  // This part prepares the message to be sent
  // The 'parse_mode=HTML' allows you to use bold (<b>), italic (<i>), etc.
  var url = "https://api.telegram.org/bot" + botToken + "/sendMessage?chat_id=" + chatId + "&text=" + encodeURIComponent(message) + "&parse_mode=HTML";
  
  var options = {
    'method': 'get' // Telegram API uses a GET request for sending messages this way
  };

  try {
    // This line actually sends the message
    UrlFetchApp.fetch(url, options);
  } catch (e) {
    // If there's an error, it will be logged for debugging
    Logger.log("Error sending Telegram message: " + e.toString());
  }
}
    

How to Use It

  1. Save the script in the Apps Script editor.

  2. Go back to your Dashboard sheet.

  3. Edit cell B64 and type Test Long Entry.

Within a few seconds, you should receive a notification in your Telegram chat or group from the bot you created. The message will contain the value from cell C60.

Comments

Popular posts from this blog

Viet Currency - Phan 20

  BASIC INDICATORS   

[VC20] Momentum indicator RSI, ADX

  I. Nguyên Tắc Nền Tảng: Xu Hướng Là Vua Bài Học Sống Còn:  Nguyên tắc quan trọng nhất là phải xác định và đi theo  xu hướng chính (Trend) . Công việc của nhà giao dịch là "dò sóng" và "nương theo sóng", không phải chống lại nó. Tránh Bắt Đỉnh, Dò Đáy:  Đừng cố gắng tìm điểm mua thấp nhất (bottom) và điểm bán cao nhất (top). Thay vào đó, hãy tập trung kiếm lợi nhuận ở  "khúc giữa" của xu hướng  để đảm bảo sự an toàn và bền vững. II. Định Nghĩa Cốt Lõi: Phân Biệt Rõ Trend và Momentum Trend (Xu hướng):  Là  hướng đi  của thị trường (lên, xuống, hoặc đi ngang). Đây là yếu tố quyết định cho việc mua hay bán. Momentum (Động lượng):  Là  Rate of Change  (Tốc độ/Cường độ thay đổi) của giá. Nó được dùng để đo lường  SỨC MẠNH (Strength)  của giá, chứ  không thể dùng để đo hướng đi . III. Cách Sử Dụng Các Chỉ Báo Kỹ Thuật Một Cách Hiệu Quả Luô...

VietCurrency Lesson - Summary version

  Contents LESSON 1 . 1 LESSON 2 . 4 LESSON 3 . 7 LESSON 4 . 10 LESSON 5 . 13 LESSON 6 . 16 LESSON 7 . 18 LESSON 8 . 21     LESSON 1 TÓM TẮT KIẾN THỨC PHÂN TÍCH KỸ THUẬT & THỊ TRƯỜNG (MARKET ANALYSIS) 1. PHÂN LOẠI CHỈ BÁO KỸ THUẬT Các chỉ báo kỹ thuật thường dùng trong trading được chia làm 6 nhóm chính: 1. Chỉ báo biến động (Volatility Indicators) Đo mức độ dao động giá/lợi suất: ATR (Average True Range), Bollinger Bands, Std Deviation, Chalkin's Volatility v.v. 2. Chỉ báo xung lượng (Momentum Indicators) Đo tốc độ, sức mạnh, động lực giá: RSI, CCI, MACD, Stochastic, Williams %R, Momentum v.v. 3. Chỉ báo chu kỳ (Cycle Indicators) Nhận diện tính chu kỳ chuyển động giá: Fibonacci, Detrended Oscillator, Cycle Lines… 4. Chỉ báo cường độ thị trường (Market Strength) Đặc biệt quan tâm đến volume, lực mua bán và các dòng vốn: OBV, MFI, Accumulation/Distribution, Chaikin Mo...