lark

package module
v0.0.0-...-60c749c Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

README

Joe Bot - Lark Adapter

Connecting joe with the Lark chat application. https://github.com/go-joe/joe


This repository contains a module for the [Joe Bot library][joe].

Getting Started

This library is packaged as Go module. You can get it via:

go get github.com/saltbo/joe-lark-adapter

Example usage

In order to connect your bot to lark you can simply pass it as module when creating a new bot:

package main

import (
	"fmt"
	"log"

	"github.com/go-joe/joe"
	larkcard "github.com/larksuite/oapi-sdk-go/v3/card"
	"go.uber.org/zap"

	lark "github.com/saltbo/joe-lark-adapter"
)

func main() {
	bot := joe.New("example", joe.WithLogLevel(zap.DebugLevel),
		lark.Adapter("cli_a7d28f1f86b89013", "WTF1wrfQzyWk0kbsghTXzfgQx7rxuKqw"),
	)
	bot.Respond("ping", func(message joe.Message) error {
		card := larkcard.NewMessageCard()
		card.Config(larkcard.NewMessageCardConfig().WideScreenMode(true))
		card.Header(larkcard.NewMessageCardHeader().Title(larkcard.NewMessageCardPlainText().Content("pong")))
		card.Elements([]larkcard.MessageCardElement{larkcard.NewMessageCardMarkdown().Content("**Name**: abc")})
		content, err := card.String()
		if err != nil {
			return err
		}

		// reply a card message
		bot.Say(message.Channel, content)
		// reply a text message
		bot.Say(message.Channel, "pong")
		return nil
	})
	bot.Brain.RegisterHandler(func(ev joe.ReceiveMessageEvent) {
		fmt.Println(ev.Text, string(ev.Data.([]byte)))
	})
	if err := bot.Run(); err != nil {
		log.Fatalln(err)
		return
	}
}

Built With

Contributing

The current implementation is rather minimal and there are many more features that could be implemented on the lark adapter so you are highly encouraged to contribute. If you want to hack on this repository, please read the short CONTRIBUTING.md guide first.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Ambor - Initial work - saltbo

See also the list of contributors who participated in this project.

License

This project is licensed under the BSD-3-Clause License - see the LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapter

func Adapter(appId, secret string) joe.Module

Types

type Message

type Message struct {
	ID string
	TextMessage
}

type TextMessage

type TextMessage struct {
	Text string `json:"text"`
}

Jump to

Keyboard shortcuts

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