Invoking Methods

Invoking Methods

Making API calls in Gogram is simple and straightforward. You can invoke methods on the client object to interact with the Telegram API. Here's an example of how to send a message to a bot using Gogram:

main.go
package main
 
import (
    "github.com/amarnathcjd/gogram/telegram"
)
 
func main() {
    client, _ := telegram.NewClient(telegram.ClientConfig{ // Create a new client
        AppID:   6,
        AppHash: "app_hash",
    })
    client.Start()
 
    client.SendMessage("@stickeroptimizerbot", "/start")
}

All methods return a response object and an error. You can check the error object to see if the method call was successful. Here's an example of how to check if the message was sent successfully:

main.go
package main
 
import (
    "fmt"
    "github.com/amarnathcjd/gogram/telegram"
)
 
func main() {
    client, _ := telegram.NewClient(telegram.ClientConfig{ // Create a new client
        AppID:   6,
        AppHash: "app_hash",
    })
    client.Start()
 
    resp, err := client.SendMessage("@stickeroptimizerbot", "/start")
    if err != nil {
        fmt.Println("Error sending message:", err)
        return
    }
 
    fmt.Println("Message sent successfully:", resp)
}