Browse Source

feat: update variable name become webhook

pull/25/head
Aldino Kemal 3 years ago
parent
commit
690e552448
  1. 2
      src/cmd/root.go
  2. 10
      src/config/settings.go
  3. 4
      src/utils/whatsapp.go

2
src/cmd/root.go

@ -37,7 +37,7 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&config.AppDebug, "debug", "d", config.AppDebug, "hide or displaying log with --debug <true/false> | example: --debug=true") rootCmd.PersistentFlags().BoolVarP(&config.AppDebug, "debug", "d", config.AppDebug, "hide or displaying log with --debug <true/false> | example: --debug=true")
rootCmd.PersistentFlags().StringVarP(&config.AppBasicAuthCredential, "basic-auth", "b", config.AppBasicAuthCredential, "basic auth credential | yourUsername:yourPassword") rootCmd.PersistentFlags().StringVarP(&config.AppBasicAuthCredential, "basic-auth", "b", config.AppBasicAuthCredential, "basic auth credential | yourUsername:yourPassword")
rootCmd.PersistentFlags().StringVarP(&config.WhatsappAutoReplyMessage, "autoreply", "", config.WhatsappAutoReplyMessage, `auto reply when received message --autoreply <string> | example: --autoreply="Don't reply this message"`) rootCmd.PersistentFlags().StringVarP(&config.WhatsappAutoReplyMessage, "autoreply", "", config.WhatsappAutoReplyMessage, `auto reply when received message --autoreply <string> | example: --autoreply="Don't reply this message"`)
rootCmd.PersistentFlags().StringVarP(&config.WhatsappAutoReplyCallbackEndpoint, "callback", "c", config.WhatsappAutoReplyMessage, `auto reply when received message --callback <string> | example: --callback="https://yourcallback.com/callback"`)
rootCmd.PersistentFlags().StringVarP(&config.WhatsappAutoReplyWebhook, "webhook", "w", config.WhatsappAutoReplyMessage, `auto reply when received message --webhook <string> | example: --webhook="https://yourcallback.com/callback"`)
} }
func runRest(cmd *cobra.Command, args []string) { func runRest(cmd *cobra.Command, args []string) {

10
src/config/settings.go

@ -20,9 +20,9 @@ var (
DBName string = "hydrogenWaCli.db" DBName string = "hydrogenWaCli.db"
WhatsappLogLevel string = "ERROR"
WhatsappAutoReplyMessage string
WhatsappAutoReplyCallbackEndpoint string
WhatsappSettingMaxFileSize int64 = 30000000 // 10MB
WhatsappSettingMaxVideoSize int64 = 30000000 // 30MB
WhatsappLogLevel string = "ERROR"
WhatsappAutoReplyMessage string
WhatsappAutoReplyWebhook string
WhatsappSettingMaxFileSize int64 = 30000000 // 10MB
WhatsappSettingMaxVideoSize int64 = 30000000 // 30MB
) )

4
src/utils/whatsapp.go

@ -184,7 +184,7 @@ func handler(rawEvt interface{}) {
_, _ = cli.SendMessage(context.Background(), evt.Info.Sender, "", &waProto.Message{Conversation: proto.String(config.WhatsappAutoReplyMessage)}) _, _ = cli.SendMessage(context.Background(), evt.Info.Sender, "", &waProto.Message{Conversation: proto.String(config.WhatsappAutoReplyMessage)})
} }
if config.WhatsappAutoReplyCallbackEndpoint != "" {
if config.WhatsappAutoReplyWebhook != "" {
go func() { go func() {
_ = sendAutoReplyCallback(evt) _ = sendAutoReplyCallback(evt)
}() }()
@ -251,7 +251,7 @@ func sendAutoReplyCallback(evt *events.Message) error {
"forwarded": evt.Message.GetGroupInviteMessage(), "forwarded": evt.Message.GetGroupInviteMessage(),
} }
postBody, _ := json.Marshal(body) postBody, _ := json.Marshal(body)
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, config.WhatsappAutoReplyCallbackEndpoint, bytes.NewBuffer(postBody))
req, err := http.NewRequestWithContext(context.Background(), http.MethodPost, config.WhatsappAutoReplyWebhook, bytes.NewBuffer(postBody))
if err != nil { if err != nil {
log.Errorf("error when create http object %v", err) log.Errorf("error when create http object %v", err)
return err return err

Loading…
Cancel
Save