当前模板如下所示:
这是用于构建此“发送秘密消息”的代码:
import (
"fmt"
"strings"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/slack-go/slack"
)
// SendMessage sends a message to the receiver through slack
func SendMessage(id uuid.UUID, sender string, receiver string, description string) error {
username := strings.Split(receiver, "@")[0]
_, _, err := rtm.PostMessage(
"@"+username,
slack.MsgOptionText(fmt.Sprintf(
"*%s has shared a secret with you!* \n*Description:* %s "+
"\nView the secret at https://whisper.sky/%s",
sender,
description,
id), false),
slack.MsgOptionAsUser(true),
)
if err != nil {
return errors.Wrap(err, "sending message through slack")
}
return nil
}
块引用
但是,在松弛的 Block Kit Builder 上,他们使用 Json,所以我的问题是,我可以在 Json 中将模板编辑为我想要的方式,并将 Json 导入我目前拥有的代码中,这样它看起来更像这样:
任何帮助将不胜感激,因为我是这个背景的新手,所以不确定要改变什么以及在哪里改变。谢谢。
这是来自块生成器的代码:
{
"blocks": [
{
"type": "header",
"text": {
"type": "plain_text",
"text": "{name} has sent you a secret!",
"emoji": true
}
},
{
"type": "divider"
},
{
"type": "section",
"fields": [
{
"type": "mrkdwn",
"text": "*Type:*\nPassword"
},
{
"type": "mrkdwn",
"text": "*For:*\nGitHub Service Account"
},
{
"type": "mrkdwn",
"text": "*Message:*\nHere's the password to the GitHub Service Account"
},
{
"type": "mrkdwn",
"text": "*Expires:*\nIn 7 Days"
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*To access this secret visit http://whisper.int.discoott.sky.com/ *"
},
"accessory": {
"type": "button",
"text": {
"type": "plain_text",
"text": "Click Here",
"emoji": true
},
"value": "access_secret_button",
"url": "https://whisper.int.discoott.sky.com/",
"action_id": "button-action"
}
},
{
"type": "divider"
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "If you did not expect this secret, you can ignore it and allow it to expire."
}
]
}
]
}
我只是不知道如何将该代码实现到我的 Go 文件中。