Last active
October 4, 2022 23:32
-
-
Save zdunecki/a10f2ed2c6ab061681cac6114055e0e9 to your computer and use it in GitHub Desktop.
Compile jsx from any language to any view format like hmtl, json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"github.com/livesession/jsxx" | |
"github.com/livesession/shared/alerts/messages" | |
) | |
func main() { | |
tpl, err := messages.SlackMessage(&messages.SlackMessageData{ | |
event: "NetError", | |
statusCode: 400, | |
url: "https://livesession.io" | |
}) | |
msg, err := jsxx.New(tpl) // msg is valid JSON for slack but can be also html or protobuf | |
slack.Send(msg) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {methodDescByCode, methodNameByCode} from "@livesession/shared" | |
function Field1() { // some field | |
} | |
function Field2() { // some field 2 | |
} | |
export function SlackMessage({data: {event, statusCode, url}}) { | |
return <attachments> | |
<blocks> | |
<text mrkdwn> | |
You have a new alert for event: \n *{event}* | |
</text> | |
<fields> | |
<field> | |
<text mrkdwn> | |
{methodNameByCode[statusCode]} {url} \n {statusCode} - {methodDescByCode[statusCode]} | |
</text> | |
</field> | |
{event === "NetErrror" ? <Field1/> : <Field2/>} | |
</fields> | |
</blocks> | |
</attachments> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment