1
0
mirror of https://github.com/badkaktus/gorocket.git synced 2024-12-12 11:15:05 +02:00
gorocket/README.md
Алексей Волегов 6c5bc5cd30 add changelog, update readme
2022-09-19 15:25:50 +03:00

86 lines
1.7 KiB
Markdown

# 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
```go
import (
"github.com/badkaktus/gorocket"
)
```
Create client
```go
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)
```
or
```go
client := gorocket.NewWithOptions("https://your-rocket-chat.com",
gorocket.WithUserID("my-user-id"),
gorocket.WithToken("my-bot-token"),
gorocket.WithTimeout(1 * time.Second),
)
```
## Manage user
```go
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
```go
// 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