gpt4 book ai didi

google-apps-script - Slack > Gsheet > VLookup > Slack

转载 作者:行者123 更新时间:2023-12-03 03:38:16 26 4
gpt4 key购买 nike

过去几周我一直在努力解决这个问题,所以我真的希望有人能帮助我解决这个问题。另外,我对代码非常陌生,这基本上激发了我对它的兴趣。

我想做的是为 Google Sheet 编写一个 Google Apps 脚本,并将其链接到入站和出站 Slack webhook,以便我可以在 Slack 中发布 PO# 等命令,并且它将填充一个使用数组公式内置 vlookup 列的电子表格,然后我想在 Slack 中发回从 Vlookup 中提取的数据。我最初有这个想法from this link

我已经非常接近了,但我不知道如何让脚本将 Vlookup 数据发布到 Slack 中。这是它的外观照片,其中突出显示的单元格是 vlookup 列:

Example Photo

下面是我正在处理的 Google Apps 脚本代码:

function doPost(req) {
var sheets = SpreadsheetApp.openById('googlesheet_link');
var params = req.parameters;

var nR = getNextRow(sheets) + 1;

if (params.token == "slack_webhook") {

//ALREADY IN SHEETS
var supplier

// PROCESS TEXT FROM MESSAGE
var textRaw = String(params.text).replace(/^\s*update\s*:*\s*/gi,'');
var text = textRaw.split(/\s*;\s*/g);

// FALL BACK TO DEFAULT TEXT IF NO UPDATE PROVIDED
var project = text[0] || "No Project Specified";
var purchaseorder = text[1] || "No update provided";
var today = text[2] || "No update provided";
var blockers = text[3] || "No update provided";

// RECORD TIMESTAMP AND USER NAME IN SPREADSHEET
sheets.getRangeByName('timestamp').getCell(nR,1).setValue(new Date());
sheets.getRangeByName('user').getCell(nR,1).setValue(params.user_name);

// RECORD UPDATE INFORMATION INTO SPREADSHEET
sheets.getRangeByName('project').getCell(nR,1).setValue(project);
sheets.getRangeByName('purchaseorder').getCell(nR,1).setValue(purchaseorder);
sheets.getRangeByName('today').getCell(nR,1).setValue(today);
sheets.getRangeByName('blockers').getCell(nR,1).setValue(blockers);


var channel = "updates";

postResponse(channel,params.channel_name,project,params.user_name,purchaseorder,today,blockers,supplier);

} else {
return;
}
}

function getNextRow(sheets) {
var timestamps = sheets.getRangeByName("timestamp").getValues();
for (i in timestamps) {
if(timestamps[i][0] == "") {
return Number(i);
break;
}
}

//AND THEN THIS IS THE RETURN//
function postResponse(channel, srcChannel, project, userName, purchaseorder, today, blockers,supplier) {

var payload = {
"channel": "#" + channel,
"username": "Trackbot3000",
"icon_emoji": ":robot_face:",
"link_names": 1,
"attachments":[
{
"fallback": "This is an update from a Slackbot integrated into your organization. Your client chose not to show the attachment.",
"pretext": "*" + project + "* posted an update for stand-up. (Posted by @" + userName + " in #" + srcChannel + ")",
"mrkdwn_in": ["pretext"],
"color": "#D00000",
"fields":[
{
"title":"Yesterday",
"value": purchaseorder,
"short":false
},
{
"title":"Today",
"value": today,
"short":false
},
{
"title":"Blockers",
"value": blockers,
"short": false
},
{
"title":"Supplier",
"value": supplier,
"short": false
}
]
}
]
};

var url = 'slack_webhook_link';
var options = {
'method': 'post',
'payload': JSON.stringify(payload)
};

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

最佳答案

我半解决了这个问题。我最终只是使用 Google Script App 代码的第一部分将 Slack 中的数据填充到 google 工作表上,并去掉了//ANDTHEN IS THE RETURN//部分。然后我对 google 工作表中的 Vlookup 列使用 IF 和 ArrayFormula。然后我使用 Automation.io 作为新行触发器,将其发送回 slack。以防万一其他人想要这样做。

关于google-apps-script - Slack > Gsheet > VLookup > Slack,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52280849/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com