Skip to content

Instantly share code, notes, and snippets.

@zdunecki
Last active October 4, 2022 23:32
Show Gist options
  • Save zdunecki/a10f2ed2c6ab061681cac6114055e0e9 to your computer and use it in GitHub Desktop.
Save zdunecki/a10f2ed2c6ab061681cac6114055e0e9 to your computer and use it in GitHub Desktop.
Compile jsx from any language to any view format like hmtl, json
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)
}
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