1646950080
Go VK bot package
This is simple VK.com bot API.
At 2019-03-01 VK was restrict messages.send for user_tokens. This bot can work with group_token, and access to chat members if has admin rights in chat. You can use v1.0.1 also, if you need only user_token access.
It can:
Installatioin:
Use go mod
For old Go versions you can also use go get github.com/nikepan/govkbot/v2
For work you need get VK access token with rights: messages,friends,offline (see below).
Quickstart
package main
import "github.com/nikepan/govkbot/v2"
import "log"
var VKAdminID = 3759927
var VKToken = "efjr98j9fj8jf4j958jj4985jfj9joijerf0fj548jf94jfiroefije495jf48"
func helpHandler(m *govkbot.Message) (reply string) {
return "help received"
}
func startHandler(m *govkbot.Message) (reply govkbot.Reply) {
keyboard := govkbot.Keyboard{Buttons: make([][]govkbot.Button, 0)}
button := govkbot.NewButton("/help", nil)
row := make([]govkbot.Button, 0)
row = append(row, button)
keyboard.Buttons = append(keyboard.Buttons, row)
return govkbot.Reply{Msg: availableCommands, Keyboard: &keyboard}
}
func errorHandler(m *govkbot.Message, err error) {
log.Fatal(err.Error())
}
func main() {
//govkbot.HandleMessage("/", anyHandler)
//govkbot.HandleMessage("/me", meHandler)
govkbot.HandleMessage("/help", helpHandler)
govkbot.HandleAdvancedMessage("/start", startHandler)
//govkbot.HandleAction("chat_invite_user", inviteHandler)
//govkbot.HandleAction("chat_kick_user", kickHandler)
//govkbot.HandleAction("friend_add", addFriendHandler)
//govkbot.HandleAction("friend_delete", deleteFriendHandler)
govkbot.HandleError(errorHandler)
govkbot.SetAutoFriend(true) // enable auto accept/delete friends
govkbot.SetDebug(true) // log debug messages
// Optional Direct VK API access
govkbot.SetAPI(VKToken, "", "") // Need only before Listen, if you use direct API
me, _ := govkbot.API.Me() // call API method
log.Printf("current user: %+v\n", me.FullName())
// Optional end
govkbot.Listen(VKToken, "", "", VKAdminID)
}
Getting group token
Open group manage and select "Work with API"
Getting user token (most likely will not work for messages)
You need standalone vk app_id. You can use any app_id from https://vk.com/apps?act=wingames, for example 4775211 (Or you can create own app and get app_id on page https://vk.com/editapp?act=create (standalone app))
You can get token from you server ip with this node.js package: https://www.npmjs.com/package/vk-auth (you need login, pass and app_id)
To manual get token you need:
https://oauth.vk.com/authorize?client_id={{app_id}}&scope=offline,groups,messages,friends&display=page&response_type=token&redirect_uri=https://oauth.vk.com/blank.html
If you receive validation check (for example, you use ip first time)
{"error":{"error_code":17,"error_msg":"Validation required: please open redirect_uri in browser ...",
"redirect_uri":"https://m.vk.com/login?act=security_check&api_hash=Qwerty1234567890"}}
you can use https://github.com/Yashko/vk-validation-node.
Author: Nikepan
Source Code: https://github.com/nikepan/govkbot
License: MIT License
1646950080
Go VK bot package
This is simple VK.com bot API.
At 2019-03-01 VK was restrict messages.send for user_tokens. This bot can work with group_token, and access to chat members if has admin rights in chat. You can use v1.0.1 also, if you need only user_token access.
It can:
Installatioin:
Use go mod
For old Go versions you can also use go get github.com/nikepan/govkbot/v2
For work you need get VK access token with rights: messages,friends,offline (see below).
Quickstart
package main
import "github.com/nikepan/govkbot/v2"
import "log"
var VKAdminID = 3759927
var VKToken = "efjr98j9fj8jf4j958jj4985jfj9joijerf0fj548jf94jfiroefije495jf48"
func helpHandler(m *govkbot.Message) (reply string) {
return "help received"
}
func startHandler(m *govkbot.Message) (reply govkbot.Reply) {
keyboard := govkbot.Keyboard{Buttons: make([][]govkbot.Button, 0)}
button := govkbot.NewButton("/help", nil)
row := make([]govkbot.Button, 0)
row = append(row, button)
keyboard.Buttons = append(keyboard.Buttons, row)
return govkbot.Reply{Msg: availableCommands, Keyboard: &keyboard}
}
func errorHandler(m *govkbot.Message, err error) {
log.Fatal(err.Error())
}
func main() {
//govkbot.HandleMessage("/", anyHandler)
//govkbot.HandleMessage("/me", meHandler)
govkbot.HandleMessage("/help", helpHandler)
govkbot.HandleAdvancedMessage("/start", startHandler)
//govkbot.HandleAction("chat_invite_user", inviteHandler)
//govkbot.HandleAction("chat_kick_user", kickHandler)
//govkbot.HandleAction("friend_add", addFriendHandler)
//govkbot.HandleAction("friend_delete", deleteFriendHandler)
govkbot.HandleError(errorHandler)
govkbot.SetAutoFriend(true) // enable auto accept/delete friends
govkbot.SetDebug(true) // log debug messages
// Optional Direct VK API access
govkbot.SetAPI(VKToken, "", "") // Need only before Listen, if you use direct API
me, _ := govkbot.API.Me() // call API method
log.Printf("current user: %+v\n", me.FullName())
// Optional end
govkbot.Listen(VKToken, "", "", VKAdminID)
}
Getting group token
Open group manage and select "Work with API"
Getting user token (most likely will not work for messages)
You need standalone vk app_id. You can use any app_id from https://vk.com/apps?act=wingames, for example 4775211 (Or you can create own app and get app_id on page https://vk.com/editapp?act=create (standalone app))
You can get token from you server ip with this node.js package: https://www.npmjs.com/package/vk-auth (you need login, pass and app_id)
To manual get token you need:
https://oauth.vk.com/authorize?client_id={{app_id}}&scope=offline,groups,messages,friends&display=page&response_type=token&redirect_uri=https://oauth.vk.com/blank.html
If you receive validation check (for example, you use ip first time)
{"error":{"error_code":17,"error_msg":"Validation required: please open redirect_uri in browser ...",
"redirect_uri":"https://m.vk.com/login?act=security_check&api_hash=Qwerty1234567890"}}
you can use https://github.com/Yashko/vk-validation-node.
Author: Nikepan
Source Code: https://github.com/nikepan/govkbot
License: MIT License
1599854400
Go announced Go 1.15 version on 11 Aug 2020. Highlighted updates and features include Substantial improvements to the Go linker, Improved allocation for small objects at high core counts, X.509 CommonName deprecation, GOPROXY supports skipping proxies that return errors, New embedded tzdata package, Several Core Library improvements and more.
As Go promise for maintaining backward compatibility. After upgrading to the latest Go 1.15 version, almost all existing Golang applications or programs continue to compile and run as older Golang version.
#go #golang #go 1.15 #go features #go improvement #go package #go new features
1655592960
Echotron is a concurrent library for telegram bots written in pure Go.
Fetch with
go get github.com/NicoNex/echotron/v3
Echotron is heavily based on concurrency: for example, every call to the Update
method of each bot is executed on a different goroutine. This makes sure that, even if one instance of the bot is deadlocked, the other ones keep running just fine, making the bot work for other users without any issues and/or slowdowns.
Echotron is designed to be as similar to the official Telegram API as possible, but there are some things to take into account before starting to work with this library.
sendMessage
becomes SendMessage
chat_id
(or, in this case, chatID
) type supported is int64
, instead of the "Integer or String" requirement of the official API. That's because numeric IDs can't change in any way, which isn't the case with text-based usernames.InputFile
type parameter. InputFile
is a struct with unexported fields, since only three combination of fields are valid, which can be obtained through the methods NewInputFileID
, NewInputFilePath
and NewInputFileBytes
.MessageIDOptions
type parameter. MessageIDOptions
is another struct with unexported fields, since only two combination of field are valid, which can be obtained through the methods NewMessageID
and NewInlineMessageID
.nil
is more than enough. Refer to the docs to check for each method's optional parameters struct: it's the type of the opts
parameter.ParseMode
, ChatAction
and InlineQueryType
. For a full list of custom hardcoded parameters, refer to the docs for each custom type: by clicking on the type's name, you'll get the source which contains the possible values for that type.A very simple implementation:
package main
import (
"log"
"github.com/NicoNex/echotron/v3"
)
// Struct useful for managing internal states in your bot, but it could be of
// any type such as `type bot int64` if you only need to store the chatID.
type bot struct {
chatID int64
echotron.API
}
const token = "YOUR TELEGRAM TOKEN"
// This function needs to be of type 'echotron.NewBotFn' and is called by
// the echotron dispatcher upon any new message from a chatID that has never
// interacted with the bot before.
// This means that echotron keeps one instance of the echotron.Bot implementation
// for each chat where the bot is used.
func newBot(chatID int64) echotron.Bot {
return &bot{
chatID,
echotron.NewAPI(token),
}
}
// This method is needed to implement the echotron.Bot interface.
func (b *bot) Update(update *echotron.Update) {
if update.Message.Text == "/start" {
b.SendMessage("Hello world", b.chatID, nil)
}
}
func main() {
// This is the entry point of echotron library.
dsp := echotron.NewDispatcher(token, newBot)
log.Println(dsp.Poll())
}
Functional example with bot internal states:
package main
import (
"log"
"strings"
"github.com/NicoNex/echotron/v3"
)
// Recursive type definition of the bot state function.
type stateFn func(*echotron.Update) stateFn
type bot struct {
chatID int64
state stateFn
name string
echotron.API
}
const token = "YOUR TELEGRAM TOKEN"
func newBot(chatID int64) echotron.Bot {
bot := &bot{
chatID: chatID,
API: echotron.NewAPI(token),
}
// We set the default state to the bot.handleMessage method.
bot.state = bot.handleMessage
return bot
}
func (b *bot) Update(update *echotron.Update) {
// Here we execute the current state and set the next one.
b.state = b.state(update)
}
func (b *bot) handleMessage(update *echotron.Update) stateFn {
if strings.HasPrefix(update.Message.Text, "/set_name") {
b.SendMessage("Send me my new name!", b.chatID, nil)
// Here we return b.handleName since next time we receive a message it
// will be the new name.
return b.handleName
}
return b.handleMessage
}
func (b *bot) handleName(update *echotron.Update) stateFn {
b.name = update.Message.Text
b.SendMessage(fmt.Sprintf("My new name is %q", b.name), b.chatID, nil)
// Here we return b.handleMessage since the next time we receive a message
// it will be handled in the default way.
return b.handleMessage
}
func main() {
dsp := echotron.NewDispatcher(token, newBot)
log.Println(dsp.Poll())
}
Example with self destruction for lower RAM usage:
package main
import (
"log"
"time"
"github.com/NicoNex/echotron/v3"
)
type bot struct {
chatID int64
echotron.API
}
const token = "YOUR TELEGRAM TOKEN"
var dsp echotron.Dispatcher
func newBot(chatID int64) echotron.Bot {
bot := &bot{
chatID,
echotron.NewAPI(token),
}
go bot.selfDestruct(time.After(time.Hour))
return bot
}
func (b *bot) selfDestruct(timech <- chan time.Time) {
<-timech
b.SendMessage("goodbye", b.chatID, nil)
dsp.DelSession(b.chatID)
}
func (b *bot) Update(update *echotron.Update) {
if update.Message.Text == "/start" {
b.SendMessage("Hello world", b.chatId, nil)
}
}
func main() {
dsp = echotron.NewDispatcher(token, newBot)
log.Println(dsp.Poll())
}
package main
import "github.com/NicoNex/echotron/v3"
type bot struct {
chatID int64
echotron.API
}
const token = "YOUR TELEGRAM TOKEN"
func newBot(chatID int64) echotron.Bot {
return &bot{
chatID,
echotron.NewAPI(token),
}
}
func (b *bot) Update(update *echotron.Update) {
if update.Message.Text == "/start" {
b.SendMessage("Hello world", b.chatID, nil)
}
}
func main() {
dsp := echotron.NewDispatcher(token, newBot)
dsp.ListenWebhook("https://example.com:443/my_bot_token")
}
This is an example for a custom http.Server which handles your own specified routes and also the webhook route which is specified by ListenWebhook.
package main
import (
"github.com/NicoNex/echotron/v3"
"context"
"log"
"net/http"
)
type bot struct {
chatID int64
echotron.API
}
const token = "YOUR TELEGRAM TOKEN"
func newBot(chatID int64) echotron.Bot {
return &bot{
chatID,
echotron.NewAPI(token),
}
}
func (b *bot) Update(update *echotron.Update) {
if update.Message.Text == "/start" {
b.SendMessage("Hello world", b.chatID, nil)
}
}
func main() {
termChan := make(chan os.Signal, 1) // Channel for terminating the app via os.Interrupt signal
signal.Notify(termChan, syscall.SIGINT, syscall.SIGTERM)
mux := http.NewServeMux()
mux.HandleFunc("/login", func(w http.ResponseWriter, r *http.Request) {
// Handle user login
})
mux.HandleFunc("/logout", func(w http.ResponseWriter, r *http.Request) {
// Handle user logout
})
mux.HandleFunc("/about", func(w http.ResponseWriter, r *http.Request) {
// Tell something about your awesome telegram bot
})
// Set custom http.Server
server := &http.Server{Addr: ":8080", Handler: mux}
go func() {
<-termChan
// Perform some cleanup..
if err := server.Shutdown(context.Background()); err != nil {
log.Print(err)
}
}()
// Capture the interrupt signal for app termination handling
dsp := echotron.NewDispatcher(token, newBot)
dsp.SetHTTPServer(server)
// Start your custom http.Server with a registered /my_bot_token handler.
log.Println(dsp.ListenWebhook("https://example.com/my_bot_token"))
}
Author: NicoNex
Source Code: https://github.com/NicoNex/echotron
License: LGPL-3.0 license
1597848999
Created by Google researchers, Go is a popular open-source programming language. The language includes many intuitive features, including a garbage collector, cross-platform, efficient concurrency, among others.
According to the Stack Overflow Developer Survey 2020, Go language is not only the fifth most loved programming language but also fetches the programmers the third-highest salary among other languages.
Below here, we list down the top machine learning libraries in Go language.
#opinions #go language #google ml tools #machine learning libraries #ml libraries #ml libraries in go
1624410000
Create a Twitter bot with Python that tweets images or status updates at a set interval. The Python script also scrapes the web for data.
📺 The video in this post was made by freeCodeCamp.org
The origin of the article: https://www.youtube.com/watch?v=8u-zJVVVhT4&list=PLWKjhJtqVAbnqBxcdjVGgT3uVR10bzTEB&index=14
🔥 If you’re a beginner. I believe the article below will be useful to you ☞ What You Should Know Before Investing in Cryptocurrency - For Beginner
⭐ ⭐ ⭐The project is of interest to the community. Join to Get free ‘GEEK coin’ (GEEKCASH coin)!
☞ **-----CLICK HERE-----**⭐ ⭐ ⭐
Thanks for visiting and watching! Please don’t forget to leave a like, comment and share!
#python #a twitter bot #a twitter bot with python #bot #bot with python #create a twitter bot with python