forked from go-telegram-bot-api/telegram-bot-api
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from iamwavecut/master
Tidy up versioning situation, cleanup tests
- Loading branch information
Showing
7 changed files
with
271 additions
and
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"time" | ||
|
||
api "github.com/OvyFlash/telegram-bot-api" | ||
) | ||
|
||
// func main() { polling_echo() } | ||
|
||
func polling_echo() { | ||
bot, err := api.NewBotAPI("MyAwesomeBotToken") | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
bot.Debug = true | ||
|
||
log.Printf("Authorized on account %s", bot.Self.UserName) | ||
|
||
updateConfig := api.NewUpdate(0) | ||
updateConfig.Timeout = 60 | ||
|
||
// Empty list allows all updates excluding | ||
// UpdateTypeChatMember, UpdateTypeMessageReaction and UpdateTypeMessageReactionCount | ||
updateConfig.AllowedUpdates = []string{ | ||
api.UpdateTypeMessage, | ||
api.UpdateTypeEditedMessage, | ||
api.UpdateTypeChannelPost, | ||
api.UpdateTypeEditedChannelPost, | ||
api.UpdateTypeBusinessConnection, | ||
api.UpdateTypeBusinessMessage, | ||
api.UpdateTypeEditedBusinessMessage, | ||
api.UpdateTypeDeletedBusinessMessages, | ||
api.UpdateTypeMessageReaction, | ||
api.UpdateTypeMessageReactionCount, | ||
api.UpdateTypeInlineQuery, | ||
api.UpdateTypeChosenInlineResult, | ||
api.UpdateTypeCallbackQuery, | ||
api.UpdateTypeShippingQuery, | ||
api.UpdateTypePreCheckoutQuery, | ||
api.UpdateTypePurchasedPaidMedia, | ||
api.UpdateTypePoll, | ||
api.UpdateTypePollAnswer, | ||
api.UpdateTypeMyChatMember, | ||
api.UpdateTypeChatMember, | ||
api.UpdateTypeChatJoinRequest, | ||
api.UpdateTypeChatBoost, | ||
api.UpdateTypeRemovedChatBoost, | ||
} | ||
|
||
updatesChannel := bot.GetUpdatesChan(updateConfig) | ||
|
||
// Optional: wait for updates and clear them if you don't want to handle | ||
// a large backlog of old messages | ||
time.Sleep(time.Millisecond * 500) | ||
updatesChannel.Clear() | ||
|
||
for update := range updatesChannel { | ||
if update.Message == nil { | ||
continue | ||
} | ||
|
||
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text) | ||
|
||
// Send an echo reply to the message | ||
msg := api.NewMessage(update.Message.Chat.ID, update.Message.Text) | ||
msg.ReplyParameters.MessageID = update.Message.MessageID | ||
|
||
bot.Send(msg) | ||
} | ||
} |
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,43 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
api "github.com/OvyFlash/telegram-bot-api" | ||
) | ||
|
||
// func main() { polling_inline_query() } | ||
|
||
func polling_inline_query() { | ||
bot, err := api.NewBotAPI("MyAwesomeBotToken") // create new bot | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
log.Printf("Authorized on account %s", bot.Self.UserName) | ||
|
||
updateConfig := api.NewUpdate(0) | ||
updateConfig.Timeout = 60 | ||
|
||
updatesChannel := bot.GetUpdatesChan(updateConfig) | ||
|
||
for update := range updatesChannel { | ||
if update.InlineQuery == nil { // if no inline query, skip update | ||
continue | ||
} | ||
|
||
article := api.NewInlineQueryResultArticle(update.InlineQuery.ID, "Echo", update.InlineQuery.Query) | ||
article.Description = update.InlineQuery.Query | ||
|
||
inlineConfig := api.InlineConfig{ | ||
InlineQueryID: update.InlineQuery.ID, | ||
IsPersonal: true, | ||
CacheTime: 0, | ||
Results: []interface{}{article}, | ||
} | ||
|
||
if _, err := bot.Request(inlineConfig); err != nil { | ||
log.Println(err) | ||
} | ||
} | ||
} |
Oops, something went wrong.