我可以使用 Json 构建模板并将其集成到我的应用程序中以使 ​​Slackbot 更具表现力吗?

问题描述

当前模板如下所示:

enter image description here

这是用于构建此“发送秘密消息”的代码


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 导入我当前拥有的代码中,使其看起来更像这样:

>

enter image description here

任何帮助将不胜感激,因为我是这个背景的新手,所以不确定要更改什么以及在哪里更改。谢谢。

这是块生成器的代码

{
    "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."
                }
            ]
        }
    ]
}

我只是不知道如何将该代码实现到我的 Go 文件中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)