8000 GitHub - faridyusof727/gochat: A simple Go library for interacting with Google Chat API.
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

faridyusof727/gochat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Chat

A simple Go library for interacting with Google Chat API.

Installation

go get github.com/faridyusof727/gochat@v0.1.5

Features

  • Send messages to Google Chat
  • Start or reply to threads
  • Simple and easy-to-use interface
  • Custom format of your message (v0.1.3)
  • Send message with normal text (v0.1.5)

Usage

Initialize Client

client, err := gochat.New(
    gochat.WithConfig(
        "YOUR_SPACE_ID",
        "YOUR_API_KEY",
        "YOUR_TOKEN",
    ),
)
if err != nil {
    log.Fatal(err)
}

// Or...

client, err := gochat.New(
    gochat.WithWebhookURL("<Your webhook url>"),
)
if err != nil {
    log.Fatal(err)
}

Send Simple Message

response, err := client.StdMessenger().SendMessage("Hello, world!")
if err != nil {
    log.Fatal(err)
}

Send Simple Message with formatting

// Create a formatter
f := gochat.NewFormatter()
    f.Bold("Main Title").
        NewLine().
        Italic("Username: johndoe").
        NewLine().
        NewLine().
        List([]string{"Name: John Doe", "Age: 20", "Category: 2A"}).
        NewLine().
        Code("package main\n\nimport \"fmt\"\n\nfunc main() {\n\tfmt.Println(\"Hello, world!\")")

// Send message with formatting
response, err := client.StdMessenger().SendMessage(f.ToString())
if err != nil {
    log.Fatal(err)
}

Send Message in Thread

// Start or reply to a thread
response, err := client.StdMessenger().StartOrReplyThread(
    "Hello, world!",
    "unique-thread-key",
)
if err != nil {
    log.Fatal(err)
}

// Send another message in the same thread
response, err = client.StdMessenger().StartOrReplyThread(
    "This is a reply",
    "unique-thread-key",
)
if err != nil {
    log.Fatal(err)
}

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

A simple Go library for interacting with Google Chat API.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

0