Skip to content

elonzh/trumpet

Repository files navigation

🎺trumpet GitHub release (latest by date) Docker Pulls GolangCI GitHub Workflow Status GitHub license

Webhook message transform service


English | 简体中文

Usage

Quick start

docker run -d -p 8080:8080 elonzh/trumpet
feishu_webhook='<your-feishu-webhook-url>'
curl "http://127.0.0.1:8080/transformers/dingtalk-to-feishu?trumpet_to=${feishu_webhook}" \
    -v -X "POST" -H "Content-Type: application/json" \
    -d '{"msgtype": "text", "text": {"content": "message from trumpet!"}}'

You can mount the configuration in the default configuration path /app/config.yaml, or provide the -c/--config parameter to provide the configuration file path.

Builtin transformers

DingTalk Feishu/Lark

Customize transformers

Starlark is a dialect of Python intended for use as a configuration language.

The message transformer are written by Starlark language, and what you need to do is defining a transform function, modifying the incoming request accordingly, for example:

def transform(request):
    # print(requst["headers"])
    # print(requst["body"])
    msg_type = request["body"]["msg_type"]
    body = {}
    if msg_type == "text":
        body = {
            "msgtype": "text",
            "text": {"content": request["body"]["content"]["text"]},
        }
    request["body"] = body
    return request

Deploy to Kubernetes

The configuration file deployed to the Kubernetes cluster is provided in the manifests folder, you can make adjustments according to your needs.

Contribute

If you want to add or update builtin transformers, just make a pull request!