我尝试通过回复消息中的某些关键字来让slackbot提供技术支持。
但是,它的响应会使它所在的通道混乱。
因此,我希望我的Slackbot在原始消息下在一个线程中答复,就像我自己回答问题时所做的那样。
从Slack文档中,我知道应该可以在线程中回复消息。我应该以某种方式使用thread_ts
,但是我无法使其正常工作。
var POST_MESSAGE_ENDPOINT = 'https://slack.com/api/chat.postMessage';
var TEXTS = [
'Hi there! Maybe I can help you?',
];
//Reply to within a thread:
//data '{"channel":"CHANNEL-ID", "text":"curl", "thread_ts":"THREAD-TS"}'
function doPost(e){
var event = JSON.parse(e.postData.contents).event;
if(event.hasOwnProperty('bot_id')){
return;
}else if(event.text.match(/(log.?in)|(inlog)|(logging?)/)){
postLogin(event, ['login']);
}else if(event.text.match(/(syncing)|(sync)|(sync$$)/)){
postSyncing(event, ['syncing']);
}else if(event.text.match(/(issues?)|(problem)/)){
postIssueOptions(event, ['issue']);
}
}
function postLogin(event, keywords){
var url1 = "<https://docs.google.com/document/d/1rcaGjyAMFpo9tG9YAgTpTFlxPZq5luwBlM3gMVCL9eI/edit|Runner can not login after changing password>";
var url2 = "<https://docs.google.com/document/d/1rcaGjyAMFpo9tG9YAgTpTFlxPZq5luwBlM3gMVCL9eI/edit|Runner forgot password>";
var url3 = "<https://docs.google.com/document/d/1rcaGjyAMFpo9tG9YAgTpTFlxPZq5luwBlM3gMVCL9eI/edit|Other login issue>";
var random_params = Math.floor(Math.random() * TEXTS.length);
var payload = {token:SLACK_ACCESS_TOKEN, channel:event.channel, text:TEXTS[random_params] + '\n' + url1+'\n'+url2+'\n'+url3};
UrlFetchApp.fetch(POST_MESSAGE_ENDPOINT, {method: 'post', payload:payload});
}
function postSyncing(event, keywords){
var url1 = "<https://docs.google.com/document/d/1rcaGjyAMFpo9tG9YAgTpTFlxPZq5luwBlM3gMVCL9eI/edit|Syncing does not work>";
var url2 = "<https://docs.google.com/document/d/1rcaGjyAMFpo9tG9YAgTpTFlxPZq5luwBlM3gMVCL9eI/edit|Yesterday's trips are still showing>";
var random_params = Math.floor(Math.random() * TEXTS.length);
var payload = {token:SLACK_ACCESS_TOKEN, channel:event.channel, text:TEXTS[random_params] + '\n' + url1+'\n'+url2};
UrlFetchApp.fetch(POST_MESSAGE_ENDPOINT, {method: 'post', payload:payload});
}
function postIssueOptions(event, keywords){
var url1 = "<https://docs.google.com/document/d/1rcaGjyAMFpo9tG9YAgTpTFlxPZq5luwBlM3gMVCL9eI/edit|Delivery missing in trip>";
var url2 = "<https://docs.google.com/document/d/1rcaGjyAMFpo9tG9YAgTpTFlxPZq5luwBlM3gMVCL9eI/edit|Runner App directs Runner back to hub>";
var url3 = "<https://docs.google.com/document/d/1rcaGjyAMFpo9tG9YAgTpTFlxPZq5luwBlM3gMVCL9eI/edit|Trip assignment does not work>";
var random_params = Math.floor(Math.random() * TEXTS.length);
var payload = {token:SLACK_ACCESS_TOKEN, channel:event.channel, text:TEXTS[random_params] + '\n' + url1+'\n'+url2+'\n'+url3};
UrlFetchApp.fetch(POST_MESSAGE_ENDPOINT, {method: 'post', payload:payload});
}
最佳答案
要为现有消息打开新线程,您需要做的就是发布新消息,该消息的thread_ts
参数设置为您要回复的消息的ts
值。
在这个稍微过时但仍然相关的overview of how threading works中,也很好地解释了整个线程的概念。
关于javascript - 如何使我的slackbot在线程中回复,而不是使用Google App脚本在整个 channel 中回复,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58608276/