bob-the-bot

module
v0.0.0-...-d0127fe Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2022 License: MIT

README ΒΆ

Bob the Bot

Steps

01) Open this project with Gitpod

this is a wip 🚧

When the project is opened with Gitpod, all dependencies are installed (see .gitpod.yml)

02) Generate the project
cabu generate service-post bob
cd bob
go mod tidy

when cabu is run for the first time, it will pull the Capsule Builder Docker image

Source code generated

bob.go

package main

import (
	hf "github.com/bots-garden/capsule/capsulemodule/hostfunctions"
	/* string to json */
	"github.com/tidwall/gjson"
	/* create json string */
	"github.com/tidwall/sjson"
)

func main() {
	hf.SetHandleHttp(Handle)
}

func Handle(request hf.Request) (response hf.Response, errResp error) {
	
	hf.Log("πŸ“ Body: " + request.Body)
	hf.Log("πŸ“ URI: " + request.Uri)
	hf.Log("πŸ“ Method: " + request.Method)

	name := gjson.Get(request.Body, "name")
	
	headersResp := map[string]string{
		"Content-Type": "application/json; charset=utf-8",
	}

	jsondoc := `{"message": ""}`
	jsondoc, _ = sjson.Set(jsondoc, "message", "πŸ‘‹ hello " + name.Str)

	return hf.Response{Body: jsondoc, Headers: headersResp}, nil
}

/*
curl -v -X POST   http://localhost:8080   -H 'content-type: application/json'   -d '{"name": "Bob"}'
*/
First build
cd bob
cabu build . bob.go bob.wasm
First Run
cd bob
capsule -wasm=./bob.wasm -mode=http -httpPort=8080

Call the service:

curl -v -X POST http://localhost:8080 -H 'content-type: application/json' -d '{"name": "Bob"}'
03) Prepare WebHook
  • Go to Settings > Webhooks (Content type: application/json) / Issues + Issue comments

https://8080-botsgarden-bobthebot-3uk65iyrzav.ws-eu70.gitpod.io

/*
https://docs.github.com/en/rest/issues/comments#create-an-issue-comment

curl \
  -X POST \
  -H "Accept: application/vnd.github+json" \
  -H "Authorization: Bearer <YOUR-TOKEN>" \
  https://api.github.com/repos/OWNER/REPO/issues/ISSUE_NUMBER/comments \
  -d '{"body":"Me too"}'
*/

Directories ΒΆ

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL