写了一篇使用感受,接下来就是细致的优化啦!
Ran-Xing opened this issue · 12 comments
这篇文章仅授权 wecahty
关于 wechaty 使用一周的感受与教程
你被骗了!!只有标题和这一句话使用中文,其他的都是英文,请手动点击翻译
Type: Individual user
usage mode: Store messages and manage messages
How to Use
What are you going to do
-
Make for the company
-
Recommend to use
Polyglot: TypeScript,JavaScript,Java,Python,Go
Puppet-providers: Service, PadLocal, Xp, Wechat, Wechat4u
-
-
Make it for yourself
-
Recommend to use
Polyglot: JavaScript,Php,Python,Go
Puppet-providers: Service, Xp, Wechat, Wechat4u
-
-
Eazy to use
## Gateway cnpm install -g wechaty wechaty-puppet-xp wechaty gateway --puppet {WECHATY_PUPPET} --port {WECHATY_PUPPET_SERVER_PORT} --token {WECHATY_PUPPET_SERVICE_TOKEN} --puppet-token {WECHATY_TOKEN} ## Server .......
How to find Problems
example:
Network error: https://github.com/wechaty/wechaty/issues?q=network+error
Rpc error: https://github.com/wechaty/go-wechaty/search?q=err%3Arpc+error%3A+code+%3D+Unavailable+desc+%3D+connection&type=issues
How to find Document
Api : Message, Room, Friendship
Polyglot : Go, Java, Python
Puppet Providers : WeChat, XP, WeChat4U
Puppet Services : PadLocal, WXWork
Specifications : Wechaty, Plugin, Puppet, Service, Token, Gateway
Quick start
## windows puppet-xp port 30000
cnpm install -g wechaty@1.11 wechaty-puppet-xp
@wechaty gateway --puppet wechaty-puppet-xp --port 30000 --token insecure_559c97f1-c6a9-39b0-8f98-288b05f315cd --puppet-token f5c70044-42ea-12ca-ae78-b5ece72dde59
## save to bat
// 1. Viper Get config
// 2. viper.Getstring set Arg (wechaty-puppet-xp)
// 3. Third party robot corpus(tuling123)
// 4. WebHook(Dingding,Telegram)
// >>> config.yaml <<<
BOT:
CHAT: off
Wechaty:
WECHATY_PUPPET: wechaty-puppet-xp
...
// >>> main.go <<<
package main
import (
"github.com/spf13/viper"
"github.com/wechaty/go-wechaty/wechaty"
// ...
)
func init() {
log.SetPrefix("[WechatyBot] ") // 设置日志前缀
log.SetFlags(log.Ltime | log.Lshortfile)
success := "[\033[01;32m✓\033[0m] "
faild := "[\033[01;31m✗\033[0m] "
info := "[\033[01;33m➜\033[0m] "
rootPath, _ := os.Getwd()
viper.Set("rootPath", rootPath)
//...
if err = viper.ReadInConfig(); err != nil {
log.Printf("%v读取配置文件失败%v", os.Getenv("faild"), err)
} else {
viper.Set("success", success)
viper.Set("rootPath", rootPath)
//...
}
}
func main() {
Api.DingBot() // Check the dingding configuration
var bot = wechaty.NewWechaty(wechaty.WithPuppetOption(wp.Option{
Token: viper.GetString("Wechaty.WECHATY_PUPPET_SERVICE_TOKEN"),
Endpoint: viper.GetString("Wechaty.URL"),
}))
// 根据观察,这里不要设置 TOKEN 了,全部用Option吧,少年
// Token 要填写 WECHATY_PUPPET_SERVICE_TOKEN
bot.OnScan(onScan).
OnLogin(onLogin).
OnLogout(onLogout).
OnError(onError).
OnMessage(onMessage).
OnFriendship(onFriendShip)
bot.DaemonStart()
}
func onMessage(context *wechaty.Context, message *user.Message) {
if message.Self() {
log.Printf("%sBot Chat:%s %s \n", viper.GetString("info"), message.From().Name(), message.Text())
} else if message.From().ID() == viper.GetString("AdminID") {
if message.Text() == "chat.off" {
setEnv("CHAT", "off")
} else if message.Text() == "chat.on" {
setEnv("CHAT", "on")
} else {
Admin.Admin(context, message)
}
} else if message.Room() != nil {
if viper.GetString("CHAT") !="off"{
// Private.Chat(context, message)
message.Say(TulingBot(message.Text())) // TulingBot use tuling123 api
log.Printf("%s%s @我了 ta 说: %s, 回复了: %s", viper.GetString("info"), message.From().Name(), message.Text(), reply)
}
} else {
// 如果不是群消息,那就是联系人消息
if viper.GetString("CHAT") !="off"{
if string(message.Text())=="在吗?" {
message.Say("来了老弟!")
}
}
}
}
...............
Auth WrchatID == XRSec_MSG
Debug
- I am using the xp protocol and go language, so I need a gateway as support. It seems that the new version of wechaty will automatically determine whether the IP of the gateway and the server is equal to the IP of the same exit. If they are equal, there is no need to open the port, and no public IP is required
- The new version requires TLS encryption, if you need to cancel encryption, please set
WECHATY_PUPPET_SERVICE_NO_TLS_INSECURE_SERVER=true
parameter @environment
XRSec has the right to modify and interpret this article. If you want to reprint or disseminate this article, you must ensure the integrity of this article, including all contents such as copyright notice. Without the permission of the author, the content of this article shall not be modified or increased or decreased arbitrarily, and it shall not be used for commercial purposes in any way
Great summarization!
Thank you very much for the sharing, and lining forward to your revised version and creating an PR on our blog website!
xp协议,可以发视频吗。我尝试了很多方法。远程url视频。mp4,格式都没有成功过。发其他pdf格式文件可以正常发送。发视频你又解决方案吗
@XRSec that's totally fine, I'm just making a suggestion.
I hope you enjoy your Wechaty bot, have a nice day!
@XRSec that's absolutely fine, I was just making a suggestion, you can take it easy.
I hope you enjoy your Wechaty bot, have a nice day!
那你问错人了,我也是半吊子一个,我也没做过类似的需求
@huan I would like to participate in your support program as a network security maintainer, what do I need to submit for the demand contribution of product security?
Glad to know that!
I think you can contribute to the code base by creating a Pill Request, or publish a blog post in our website!
@huan I found your github token in your docker image, but it has expired. I hope you will pay attention to your privacy information
No, any language will be ok!
Pick which you most favorite of!