OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

With Apps Script, whenever changes in Goole Sheet, I'd like to get Messages in Slack

  • Thread starter Thread starter Kiwi juice
  • Start date Start date
K

Kiwi juice

Guest
I made a webpage vis Softr. If my customers encode something in the webpage, it will be encoded in Google sheet.

Whenever there are changes in google sheet, I'd like to get the messages in Slack.

I made it w/ Apps Script and could get messages in Slack but it does NOT SHOW VALUES in the celles as below.

Slack Message : Sheet: Sheet1, Cell: A130:F130, New Value:

If you know about this, please help me how I can change this cording. Thank you.

Code:
const WEBHOOK_URL = *'I encoded here the webhookurl of my slack channel'*; // 여기에 생성한 Webhook URL을 입력하세요.

function sendSlackNotification(sheetName, cell, value) {
  var message = `Sheet: ${sheetName}, Cell: ${cell}, New Value: ${value}`;

  Logger.log(message); // 디버깅을 위해 로그에 기록

  // 슬랙에 알림 보내기
  var payload = {
    text: message
  };

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

  UrlFetchApp.fetch(WEBHOOK_URL, options);
}

function onChange(e) {
  var sheet = e.source.getActiveSheet();
  var sheetName = sheet.getName();

  // 변경된 범위를 가져오기 위해 마지막 편집 시간을 이용
  var lastRow = sheet.getLastRow();
  var lastColumn = sheet.getLastColumn();
  var range = sheet.getRange(lastRow, 1, 1, lastColumn);
  var cell = range.getA1Notation();
  var value = range.getValue();

  sendSlackNotification(sheetName, cell, value);
}

<p>I made a webpage vis Softr. If my customers encode something in the webpage, it will be encoded in Google sheet.</p>
<p>Whenever there are changes in google sheet, I'd like to get the messages in Slack.</p>
<p>I made it w/ Apps Script and could get messages in Slack but it does NOT SHOW VALUES in the celles as below.</p>
<p>Slack Message :
<strong>Sheet: Sheet1, Cell: A130:F130, New Value:</strong></p>
<p>If you know about this, please help me how I can change this cording.
Thank you.</p>
<pre><code>const WEBHOOK_URL = *'I encoded here the webhookurl of my slack channel'*; // 여기에 생성한 Webhook URL을 입력하세요.

function sendSlackNotification(sheetName, cell, value) {
var message = `Sheet: ${sheetName}, Cell: ${cell}, New Value: ${value}`;

Logger.log(message); // 디버깅을 위해 로그에 기록

// 슬랙에 알림 보내기
var payload = {
text: message
};

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

UrlFetchApp.fetch(WEBHOOK_URL, options);
}

function onChange(e) {
var sheet = e.source.getActiveSheet();
var sheetName = sheet.getName();

// 변경된 범위를 가져오기 위해 마지막 편집 시간을 이용
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var range = sheet.getRange(lastRow, 1, 1, lastColumn);
var cell = range.getA1Notation();
var value = range.getValue();

sendSlackNotification(sheetName, cell, value);
}
</code></pre>
 

Latest posts

H
Replies
0
Views
1
Hür Doğan ÜNLÜ
H
Top