1
0
mirror of https://github.com/badkaktus/gorocket.git synced 2024-12-12 11:15:05 +02:00
golang library for rocket.chat
Go to file
2020-09-08 23:16:54 +03:00
.gitignore init commit 2020-04-30 17:36:31 +03:00
authentication.go add channels 2020-08-25 00:21:08 +03:00
autotranslate.go add auth, translate. edit new client. 2020-06-20 18:14:33 +03:00
channels.go finish channels 2020-08-29 22:56:09 +03:00
chat.go add chat methods 2020-09-08 00:27:48 +03:00
go.mod gomod 2020-05-04 22:25:06 +03:00
gorocket.go add auth, translate. edit new client. 2020-06-20 18:14:33 +03:00
groups.go add group endpoint 2020-09-07 23:29:07 +03:00
hooks.go hooks edit 2020-05-06 09:43:20 +03:00
info.go add channels 2020-08-25 00:21:08 +03:00
README.md add README.md 2020-09-08 23:16:54 +03:00
users.go user finished 2020-08-07 12:09:49 +03:00

Golang Rocket Chat REST API client

Use this simple client if you need to connect to Rocket Chat in Golang.

How to use

Just import

import (
	"github.com/badkaktus/gorocket"
)

Create client

client := gorocket.NewClient("https://your-rocket-chat.com")

// login as the main admin user
login := gorocket.LoginPayload{
    User:     "admin-login",
    Password: "admin-password",
}

lg, err := client.Login(&login)

if err != nil {
    fmt.Printf("Error: %+v", err)
}
fmt.Printf("I'm %s", lg.Data.Me.Username)

Manage user

str := gorocket.NewUser{
    Email:                 "test@email.com",
    Name:                  "John Doe",
    Password:              "simplepassword",
    Username:              "johndoe",
    Active:                true,
}

me, err := client.UsersCreate(&str)
if err != nil {
    fmt.Printf("Error: %+v", err)
}
fmt.Printf("User was created %t", me.Success)

Post a message

// create a new channel
str := gorocket.CreateChannelRequest{
    Name:     "newchannel",
}

channel, err := client.CreateChannel(&str)
if err != nil {
    fmt.Printf("Error: %+v", err)
}
fmt.Printf("Channel was created %t", channel.Success)
// post a message
str := gorocket.Message{
    Channel:     "somechannel",
    Text:        "Hey! This is new message from Golang REST Client",
}

msg, err := client.PostMessage(&str)
if err != nil {
    fmt.Printf("Error: %+v", err)
}
fmt.Printf("Message was posted %t", msg.Success)

PS

Feel free to create issue for add new endpoint to this client