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   

Viet Currency - Phan 21

  Trading technique with ADX        Trong western T/A nó có 4 cái indicators chính mà trên hầu hết các trading desks trên thế giới đều xài. Đó là: MACD, RSI, ADX, và gần đây nữa là CCI. Bên stocks thì MACD là dẫn đầu. MACD, nếu biết xài, thì có thể nói nó đúng chừng 80% trở lên trong US stocks. VN thì tôi không biết. RSI thì tôi không rành lém. Tôi thấy thằng Q đó quờ quạng làm sao ấy. Nhưng có rất nhiều người thề sống chít với nó. Và họ đều là cao thủ hơn tôi, nên tôi không dám chê thằng Q đó nhiều. Vì trong đời tôi gặp ít nhất là 5 cụ. Cụ ở đây có nghĩa là ít gì cũng 50 năm (yeah..50 years on the Street). Cụ nào cũng khen nó còn hơn thuốc Tiên. Có 2 lão dám nói là chỉ cần nhìn RSI thui, không cần nhìn giá mà vẫn trade được như thường. Anyway, thằng thứ 3 là ADX. ADX ở tại Mỹ, nhất là các trading desks mà tôi làm việc khi xưa, đều xài nó cho Currency market. Xin mở dấu hoặc ở đây để phân biệt được cái gọi là currency market và cái gọi là forex marke...

Viet Currency - Phan 22

    5. STOCHASTIC:  Anh VC cho Q hoỉ, nếu nhìn lại năm 2006, 2/8 là đáy, nhưng trong suốt xu hướng giảm giá Momentum giao động thấp nhất là -100. Còn VNI hiện tại, dù chưa giảm nhiều như vậy, nhưng Momentum đã <-100 và đang từ dưới đi lên, điều đó trong PTKT có phản ánh điều gì không?      Momentum nó khác với giá. Nó là sự thay đổi của giá QUA thời gian. Trong một khoảng thời gian nhất định nào đó nếu giá thay đổi nhiều thì momentum sẽ đi xuống và ngược lại. Tôi không xài momentum vì trong giai đoạn này tôi chỉ nhìn trend qua các điểm reactionary points để xác định hướng đi của nó. Khi trend được xác định rồi thì tôi mới xài momentum để dò la sức mạnh của nó. Như cái chart của tôi phía trên, nếu giá đi lên khỏi 1155 hay đi xuống điểm thấp nhất của VNI hôm tuần trước thì lúc đó mới lấy momentum ra đo. Vì lúc đó nó sẽ nói cho tôi biết cái break out (trên 1155) và cái break down có thật sự mạnh hay không? Còn bây giờ chỉ số này chỉ trade trong ...