如何解决我可以使用 Json 构建模板并将其集成到我的应用程序中以使 Slackbot 更具表现力吗?
当前模板如下所示:
这是用于构建此“发送秘密消息”的代码:
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
}
块引用
但是,在 slack 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"
},"text": "*Message:*\nHere's the password to the GitHub Service Account"
},"text": "*Expires:*\nIn 7 Days"
}
]
},"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": "context","elements": [
{
"type": "mrkdwn","text": "If you did not expect this secret,you can ignore it and allow it to expire."
}
]
}
]
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。