Browse Source

Merge b02c56c531 into 2f438c799c

pull/305/merge
TheProcedural 9 months ago
committed by GitHub
parent
commit
6d19d65a71
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      src/.env.example
  2. 9
      src/cmd/root.go
  3. 25
      src/config/settings.go
  4. 12
      src/infrastructure/whatsapp/init.go

1
src/.env.example

@ -12,5 +12,6 @@ DB_URI="file:storages/whatsapp.db?_foreign_keys=on"
WHATSAPP_AUTO_REPLY="Auto reply message"
WHATSAPP_WEBHOOK=https://webhook.site/07b69616-5943-4c7f-a8be-db4819df699e,https://webhook.site/09a38aff-d11a-4a38-a176-3f3efa0b5e8b
WHATSAPP_WEBHOOK_SECRET=super-secret-key
CALL_WEBHOOK_ON_MESSAGE_TO_SELF=false
WHATSAPP_ACCOUNT_VALIDATION=true
WHATSAPP_CHAT_STORAGE=true

9
src/cmd/root.go

@ -110,6 +110,9 @@ func initEnvConfig() {
if viper.IsSet("whatsapp_chat_storage") {
config.WhatsappChatStorage = viper.GetBool("whatsapp_chat_storage")
}
if envCallWebhookOnMessageToSelf := viper.GetBool("CALL_WEBHOOK_ON_MESSAGE_TO_SELF"); envCallWebhookOnMessageToSelf {
config.WhatsappCallWebhookOnMessageToSelf = envCallWebhookOnMessageToSelf
}
}
func initFlags() {
@ -185,6 +188,12 @@ func initFlags() {
config.WhatsappChatStorage,
`enable or disable chat storage --chat-storage <true/false>. If you disable this, reply feature maybe not working properly | example: --chat-storage=true`,
)
rootCmd.PersistentFlags().BoolVarP(
&config.WhatsappCallWebhookOnMessageToSelf,
"call-webhook-on-message-to-self", "",
config.WhatsappCallWebhookOnMessageToSelf,
`enable or disable webhook calls for messages from yourself --call-webhook-on-message-to-self <true/false> | example: --call-webhook-on-message-to-self=true`,
)
}
func initApp() {

25
src/config/settings.go

@ -24,16 +24,17 @@ var (
DBURI = "file:storages/whatsapp.db?_foreign_keys=on"
WhatsappAutoReplyMessage string
WhatsappWebhook []string
WhatsappWebhookSecret = "secret"
WhatsappLogLevel = "ERROR"
WhatsappSettingMaxImageSize int64 = 20000000 // 20MB
WhatsappSettingMaxFileSize int64 = 50000000 // 50MB
WhatsappSettingMaxVideoSize int64 = 100000000 // 100MB
WhatsappSettingMaxDownloadSize int64 = 500000000 // 500MB
WhatsappTypeUser = "@s.whatsapp.net"
WhatsappTypeGroup = "@g.us"
WhatsappAccountValidation = true
WhatsappChatStorage = true
WhatsappAutoReplyMessage string
WhatsappWebhook []string
WhatsappWebhookSecret = "secret"
WhatsappCallWebhookOnMessageToSelf = false
WhatsappLogLevel = "ERROR"
WhatsappSettingMaxImageSize int64 = 20000000 // 20MB
WhatsappSettingMaxFileSize int64 = 50000000 // 50MB
WhatsappSettingMaxVideoSize int64 = 100000000 // 100MB
WhatsappSettingMaxDownloadSize int64 = 500000000 // 500MB
WhatsappTypeUser = "@s.whatsapp.net"
WhatsappTypeGroup = "@g.us"
WhatsappAccountValidation = true
WhatsappChatStorage = true
)

12
src/infrastructure/whatsapp/init.go

@ -247,18 +247,22 @@ func handleAutoReply(evt *events.Message) {
}
func handleWebhookForward(ctx context.Context, evt *events.Message) {
// Skip webhook for specific protocol messages that shouldn't trigger webhooks
if protocolMessage := evt.Message.GetProtocolMessage(); protocolMessage != nil {
protocolType := protocolMessage.GetType().String()
// Skip EPHEMERAL_SYNC_RESPONSE but allow REVOKE and MESSAGE_EDIT
if protocolType == "EPHEMERAL_SYNC_RESPONSE" {
log.Debugf("Skipping webhook for EPHEMERAL_SYNC_RESPONSE message")
return
}
}
if len(config.WhatsappWebhook) > 0 &&
!strings.Contains(evt.Info.SourceString(), "broadcast") {
shouldCallWebhook := len(config.WhatsappWebhook) > 0 &&
!strings.Contains(evt.Info.SourceString(), "broadcast")
if isFromMySelf(evt.Info.SourceString()) && !config.WhatsappCallWebhookOnMessageToSelf {
shouldCallWebhook = false
}
if shouldCallWebhook {
go func(evt *events.Message) {
if err := forwardToWebhook(ctx, evt); err != nil {
logrus.Error("Failed forward to webhook: ", err)

Loading…
Cancel
Save