-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
31695a2
commit 79cee88
Showing
29 changed files
with
2,265 additions
and
2,123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.