Skip to content

Commit

Permalink
Push V1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AmarnathCJD committed Oct 9, 2022
1 parent 31695a2 commit 79cee88
Show file tree
Hide file tree
Showing 29 changed files with 2,265 additions and 2,123 deletions.
4 changes: 2 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,10 +422,10 @@ var errorMessages = map[string]string{
"SCHEDULE_DATE_TOO_LATE": "The date you tried to schedule is too far in the future (last known limit of 1 year and a few hours)",
"SCHEDULE_STATUS_PRIVATE": "You cannot schedule a message until the person comes online if their privacy does not show this information",
"SCHEDULE_TOO_MUCH": "You cannot schedule more messages in this chat (last known limit of 100 per chat)",
"SCORE_INVALID": "",
"SCORE_INVALID": "The given game score is invalid",
"SEARCH_QUERY_EMPTY": "The search query is empty",
"SECONDS_INVALID": "Slow mode only supports certain values (e.g. 0, 10s, 30s, 1m, 5m, 15m and 1h)",
"SEND_AS_PEER_INVALID": "",
"SEND_AS_PEER_INVALID": "The sendAs Peer is Invalid or cannot be used as Bot",
"SEND_CODE_UNAVAILABLE": "",
"SEND_MESSAGE_MEDIA_INVALID": "The message media was invalid or not specified",
"SEND_MESSAGE_TYPE_INVALID": "The message type is invalid",
Expand Down
51 changes: 18 additions & 33 deletions examples/auth/userauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,32 @@ import (
)

const (
appID = 6
appHash = ""
appID = 6
appHash = "YOUR_APP_HASH"
phoneNum = "YOUR_PHONE_NUMBER"
)

func main() {
client, err := telegram.TelegramClient(telegram.ClientConfig{
AppID: appID,
AppHash: appHash,
StringSession: "", // (if this value is specified, client.Login is not Necessary.)
// Create a new client
client, _ := telegram.TelegramClient(telegram.ClientConfig{
AppID: appID,
AppHash: appHash,
LogLevel: telegram.LogInfo,
// StringSession: "", // Uncomment this line to use string session
})

if err != nil {
// Authenticate the client using the bot token
// This will send a code to the phone number if it is not already authenticated
if _, err := client.Login(phoneNum); err != nil {
panic(err)
}

// Login with phone number, if you have a string session, you can skip this step.
// Code AuthFlow implemented
phoneNumber := "+1234567890"
if authed, err := client.Login(phoneNumber); !authed {
panic(err)
}

stringSession := client.ExportSession()
fmt.Println("String Session: ", stringSession)

me, _ := client.GetMe()
fmt.Printf("Logged in as %s\n", me.Username)

m, err := client.GetMessages("durov", &telegram.SearchOption{Limit: 1})
// Do something with the client
// ...
me, err := client.GetMe()
if err != nil {
fmt.Println(err)
} else {
fmt.Println(m[0].Marshal())
panic(err)
}

// Add handlers
client.AddMessageHandler(".start", Start)
client.Idle() // Blocks until client.Stop() is called
}

func Start(m *telegram.NewMessage) error {
_, err := m.Edit("Hello World")
return err
client.SendMessage("me", fmt.Sprintf("Hello, %s!", me.FirstName))
fmt.Println("Logged in as", me.Username)
}
108 changes: 0 additions & 108 deletions examples/bot/bot.go

This file was deleted.

45 changes: 45 additions & 0 deletions examples/bot/echobot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package examples

import (
"fmt"

"github.com/amarnathcjd/gogram/telegram"
)

const (
appID = 6
appHash = "YOUR_APP_HASH"
botToken = "YOUR_BOT_TOKEN"
)

func main() {
// Create a new client
client, _ := telegram.TelegramClient(telegram.ClientConfig{
AppID: appID,
AppHash: appHash,
LogLevel: telegram.LogInfo,
})

// Authenticate the client using the bot token
if err := client.LoginBot(botToken); err != nil {
panic(err)
}

// Add a message handler
client.AddMessageHandler(telegram.OnNewMessage, func(message *telegram.NewMessage) error {
var (
err error
)
// Print the message
fmt.Println(message.Marshal())

// Send a message
if message.IsPrivate() {
_, err = message.Respond(message)
}
return err
})

// Start polling
client.Idle()
}
40 changes: 40 additions & 0 deletions examples/getchats/getchats.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package examples

import (
"fmt"

"github.com/amarnathcjd/gogram/telegram"
)

const (
appID = 6
appHash = "YOUR_APP_HASH"
phoneNum = "YOUR_PHONE_NUMBER"
)

func main() {
// Create a new client
client, _ := telegram.TelegramClient(telegram.ClientConfig{
AppID: appID,
AppHash: appHash,
LogLevel: telegram.LogInfo,
// StringSession: "", // Uncomment this line to use string session
})

// Authenticate the client using the bot token
// This will send a code to the phone number if it is not already authenticated
if _, err := client.Login(phoneNum); err != nil {
panic(err)
}

dialogs, err := client.GetDialogs()
if err != nil {
panic(err)
}
for _, dialog := range dialogs {
switch d := dialog.(type) {
case *telegram.DialogObj:
fmt.Println(d.TopMessage)
}
}
}
38 changes: 38 additions & 0 deletions examples/inline/inlinebot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package examples

import (
"github.com/amarnathcjd/gogram/telegram"
)

const (
appID = 6
appHash = "YOUR_APP_HASH"
botToken = "YOUR_BOT_TOKEN"
)

func main() {
// Create a new client
client, _ := telegram.TelegramClient(telegram.ClientConfig{
AppID: appID,
AppHash: appHash,
LogLevel: telegram.LogInfo,
})

// Authenticate the client using the bot token
if err := client.LoginBot(botToken); err != nil {
panic(err)
}

// Add a inline query handler
client.AddInlineHandler(telegram.OnInlineQuery, HelloWorld)

// Start polling
client.Idle()
}

func HelloWorld(i *telegram.InlineQuery) error {
builder := i.Builder()
builder.Article("Hello World", "Hello World", "This is a test article")
_, err := i.Answer(builder.Results())
return err
}
6 changes: 3 additions & 3 deletions handshake.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (m *MTProto) makeAuthKey() error {
NewNonce: nonceSecond,
})
if err != nil {
log.Printf("TgCrypto - makeAuthKey: %s", err)
m.Logger.Warn(fmt.Sprintf("TgCrypto - makeAuthKey: %s", err))
return err
}

Expand All @@ -82,7 +82,7 @@ func (m *MTProto) makeAuthKey() error {
return fmt.Errorf("reqDHParams: server nonce mismatch")
}

// check of hash, trandom bytes trail removing occurs in this func already
// check of hash, random bytes trail removing occurs in this func already
decodedMessage := ige.DecryptMessageWithTempKeys(dhParams.EncryptedAnswer, nonceSecond.Int, nonceServer.Int)
data, err := tl.DecodeUnknownObject(decodedMessage)
if err != nil {
Expand Down Expand Up @@ -162,7 +162,7 @@ func (m *MTProto) makeAuthKey() error {
if !m.memorySession {
err = m.SaveSession()
if err != nil {
log.Printf("TgCrypto - savesession: %s", err)
m.Logger.Error(fmt.Sprintf("TgCrypto - makeAuthKey: %s", err))
}
}
return err
Expand Down
Loading

0 comments on commit 79cee88

Please sign in to comment.