v2.4 🚀
This commit is contained in:
parent
82df7fd935
commit
cb7836a9c2
67
README.md
67
README.md
@ -28,14 +28,15 @@ cp config/config.yaml.example local/config.yaml
|
||||
打开 [openai](https://beta.openai.com/account/api-keys) 并注册一个账号, 生成一个apiKey并把apiKey放到`local/config.yaml`
|
||||
的token下,请看如下示例:
|
||||
|
||||
大陆用户注册`openai`请参考 [注册ChatGPT详细指南](https://sms-activate.org/cn/info/ChatGPT)
|
||||
|
||||
```
|
||||
chatgpt:
|
||||
keyword: 小莫
|
||||
wechat: 小莫
|
||||
token: sk-pKHZD1fLYqXDjjsdsdsdUvIODTT3ssjdfadsJC2gTuqqhTum
|
||||
telegram: your telegram token
|
||||
```
|
||||
|
||||
大陆用户注册`openai`请参考 [注册ChatGPT详细指南](https://sms-activate.org/cn/info/ChatGPT)
|
||||
|
||||
## 运行App
|
||||
|
||||
```
|
||||
@ -47,26 +48,62 @@ go run main.go
|
||||
同时启动微信和telegram,微信登陆的地址请查看运行日志
|
||||
|
||||
```
|
||||
# apple silicon 如果不加触发关键字的话默认为: chatgpt
|
||||
docker run -d --name="wechatgpt" -e apiKey="你的chatgpt apiKey" -e wechat="触发关键字" telegram="你的telegram token" xiaomoinfo/wechatgpt:latest
|
||||
# apple silicon
|
||||
docker run -d \
|
||||
--name="wechatgpt" \
|
||||
-e apiKey="你的chatgpt apiKey" \
|
||||
-e wechat="微信触发关键字" \
|
||||
-e telegram="你的telegram token" \
|
||||
xiaomoinfo/wechatgpt:latest
|
||||
|
||||
# linux amd64 如果不加触发关键字的话默认为: chatgpt
|
||||
docker run -d --name="wechatgpt" -e apiKey="你的chatgpt apiKey" telegram="你的telegram token" -e wechat="触发关键字" xiaomoinfo/wechatgpt-amd64:latest
|
||||
# linux amd64
|
||||
docker run -d \
|
||||
--name="wechatgpt" \
|
||||
-e apiKey="你的chatgpt apiKey" \
|
||||
-e wechat="微信触发关键字" \
|
||||
-e telegram="你的telegram token" \
|
||||
xiaomoinfo/wechatgpt-amd64:latest
|
||||
|
||||
```
|
||||
|
||||
|
||||
|
||||
如果只想运行微信智能机器人的话运行下面这段代码,微信登陆的地址请查看运行日志
|
||||
|
||||
```
|
||||
# apple silicon 如果不加触发关键字的话默认为: chatgpt
|
||||
docker run -d --name wechatgpt -e apiKey="你的chatgpt apiKey" -e wechat="触发关键字" xiaomoinfo/wechatgpt:latest
|
||||
# apple silicon
|
||||
docker run -d \
|
||||
--name wechatgpt \
|
||||
-e apiKey="你的chatgpt apiKey" \
|
||||
-e wechat="微信触发关键字" \
|
||||
xiaomoinfo/wechatgpt:latest
|
||||
|
||||
# linux amd64 如果不加触发关键字的话默认为: chatgpt
|
||||
docker run -d --name wechatgpt -e apiKey="你的chatgpt apiKey" -e wechat="触发关键字" xiaomoinfo/wechatgpt-amd64:latest
|
||||
# linux amd64
|
||||
docker run -d \
|
||||
--name wechatgpt \
|
||||
-e apiKey="你的chatgpt apiKey" \
|
||||
-e wechat="微信触发关键字" \
|
||||
xiaomoinfo/wechatgpt-amd64:latest
|
||||
|
||||
```
|
||||
|
||||
如果只想运行`telegram`智能机器人的话运行下面这段代码
|
||||
|
||||
```
|
||||
# apple silicon
|
||||
docker run -d \
|
||||
--name wechatgpt \
|
||||
-e apiKey="你的chatgpt apiKey" \
|
||||
-e telegram="你的telegram token" \
|
||||
xiaomoinfo/wechatgpt:latest
|
||||
|
||||
# linux amd64
|
||||
docker run -d \
|
||||
--name wechatgpt \
|
||||
-e apiKey="你的chatgpt apiKey" \
|
||||
-e telegram="你的telegram token" \
|
||||
xiaomoinfo/wechatgpt-amd64:latest
|
||||
|
||||
```
|
||||
|
||||
<img src="screenshots/docker部署.png" alt="drawing" style="width:250px;"/>
|
||||
|
||||
### 微信
|
||||
@ -99,7 +136,7 @@ INFO[0099] 3 <Friend:wloscar>
|
||||
|
||||
### 如何使用
|
||||
|
||||
默认为`chatgpt`,如果想设置其他的触发方式可以修改`local/config.yaml`的keyword。此时,如果别人给你发消息带有关键字`chatgpt`
|
||||
默认为`chatgpt`,如果想设置其他的触发方式可以修改`local/config.yaml`的wechat。此时,如果别人给你发消息带有关键字`chatgpt`
|
||||
,你的微信就会调用`chatGPT`AI自动回复你的好友。
|
||||
当然,在群里也是可以的。
|
||||
|
||||
@ -138,7 +175,7 @@ INFO[0099] 3 <Friend:wloscar>
|
||||
|
||||
```
|
||||
chatgpt:
|
||||
keyword: 小莫
|
||||
wechat: 小莫
|
||||
token: sk-pKHZD1fLYqXDjjsdsdsdUvIODTT3ssjdfadsJC2gTuqqhTum
|
||||
telegram: 5718911250:AAhR1pn52xcCFoM_GyI2g9BaX18S7WbYviQ
|
||||
```
|
||||
|
@ -16,3 +16,10 @@ tasks:
|
||||
- docker push xiaomoinfo/wechatgpt-amd64:latest
|
||||
- docker build -t xiaomoinfo/wechatgpt:latest .
|
||||
- docker push xiaomoinfo/wechatgpt:latest
|
||||
|
||||
2.4:
|
||||
cmds:
|
||||
- docker build --platform linux/amd64 -t xiaomoinfo/wechatgpt-amd64:2.4 .
|
||||
- docker push xiaomoinfo/wechatgpt-amd64:2.4
|
||||
- docker build -t xiaomoinfo/wechatgpt:2.4 .
|
||||
- docker push xiaomoinfo/wechatgpt:2.4
|
@ -18,7 +18,10 @@ func StartTelegramBot() {
|
||||
return
|
||||
}
|
||||
botConfig := getConfig.ChatGpt
|
||||
telegramKey = botConfig.Telegram
|
||||
if botConfig.Telegram == nil {
|
||||
return
|
||||
}
|
||||
telegramKey = *botConfig.Telegram
|
||||
log.Info("读取本地本置文件中的telegram token:", telegramKey)
|
||||
} else {
|
||||
log.Info("找到环境变量: telegram token:", telegramKey)
|
||||
|
@ -3,10 +3,17 @@ package bootstrap
|
||||
import (
|
||||
"github.com/eatmoreapple/openwechat"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/wechatgpt/wechatbot/config"
|
||||
"github.com/wechatgpt/wechatbot/handler/wechat"
|
||||
"os"
|
||||
)
|
||||
|
||||
func StartWebChat() {
|
||||
keyword := getKeyword()
|
||||
if len(keyword) == 0 {
|
||||
log.Info("未配置微信关键字,不启动微信")
|
||||
return
|
||||
}
|
||||
bot := openwechat.DefaultBot(openwechat.Desktop)
|
||||
bot.MessageHandler = wechat.Handler
|
||||
bot.UUIDCallback = openwechat.PrintlnQrcodeUrl
|
||||
@ -36,11 +43,23 @@ func StartWebChat() {
|
||||
for i, group := range groups {
|
||||
log.Println(i, group)
|
||||
}
|
||||
|
||||
err = bot.Block()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func getKeyword() string {
|
||||
keyword := os.Getenv("wechat")
|
||||
if len(keyword) == 0 {
|
||||
gptConfig := config.GetConfig()
|
||||
if gptConfig != nil {
|
||||
if gptConfig.ChatGpt.Wechat != nil {
|
||||
keyword = *gptConfig.ChatGpt.Wechat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return keyword
|
||||
}
|
||||
|
@ -11,9 +11,9 @@ type Config struct {
|
||||
}
|
||||
|
||||
type ChatGptConfig struct {
|
||||
Keyword string `json:"keyword,omitempty"`
|
||||
Token string `json:"token,omitempty" json:"token,omitempty"`
|
||||
Telegram string `json:"telegram"`
|
||||
Wechat *string `json:"wechat,omitempty"`
|
||||
Token string `json:"token,omitempty" json:"token,omitempty"`
|
||||
Telegram *string `json:"telegram"`
|
||||
}
|
||||
|
||||
func LoadConfig() error {
|
||||
|
@ -1,4 +1,4 @@
|
||||
chatgpt:
|
||||
keyword: chatgpt
|
||||
token: your token
|
||||
wechat: chatgpt
|
||||
token: your chatgpt apiKey
|
||||
telegram: your telegram token
|
@ -33,17 +33,17 @@ func (gmh *GroupMessageHandler) ReplyText(msg *openwechat.Message) error {
|
||||
group := openwechat.Group{User: sender}
|
||||
log.Printf("Received Group %v Text Msg : %v", group.NickName, msg.Content)
|
||||
|
||||
keyword := os.Getenv("wechat")
|
||||
if len(keyword) == 0 {
|
||||
wechat := os.Getenv("wechat")
|
||||
if len(wechat) == 0 {
|
||||
appConfig := config.GetConfig()
|
||||
if appConfig != nil {
|
||||
keyword = appConfig.ChatGpt.Keyword
|
||||
if appConfig.ChatGpt.Wechat != nil {
|
||||
wechat = *appConfig.ChatGpt.Wechat
|
||||
} else {
|
||||
keyword = "chatgpt"
|
||||
wechat = "chatgpt"
|
||||
}
|
||||
}
|
||||
|
||||
content, key := utils.ContainsI(msg.Content, keyword)
|
||||
content, key := utils.ContainsI(msg.Content, wechat)
|
||||
if len(key) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user