| 1 | package iftttscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/ |
| 2 | |
| 3 | import ( |
| 4 | "encoding/jsonscip-go gomod github.com/golang/go/src . `encoding/json`/" |
| 5 | "fmtscip-go gomod github.com/golang/go/src . fmt/" |
| 6 | |
| 7 | "github.com/nicholas-fedor/shoutrrr/pkg/typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/" |
| 8 | ) |
| 9 | |
| 10 | // jsonPayload represents the notification payload sent to the IFTTT webhook API. |
| 11 | type jsonPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload# struct { |
| 12 | Value1scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value1. string `json:"value1"` |
| 13 | Value2scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value2. string `json:"value2"` |
| 14 | Value3scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value3. string `json:"value3"` |
| 15 | } |
| 16 | |
| 17 | // ValueFieldOne represents the Value1 field in the IFTTT payload. |
| 18 | const ( |
| 19 | ValueFieldOnescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/ValueFieldOne. = 1 // Represents Value1 field |
| 20 | ValueFieldTwoscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/ValueFieldTwo. = 2 // Represents Value2 field |
| 21 | ValueFieldThreescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/ValueFieldThree. = 3 // Represents Value3 field |
| 22 | ) |
| 23 | |
| 24 | // createJSONToSend generates a JSON payload for the IFTTT webhook API. |
| 25 | func createJSONToSendscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/createJSONToSend().(config *Configscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/Config#, message string, params *typesscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/.Paramsscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/types`/Params#) ([]byte, error) { |
| 26 | payload := jsonPayloadscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#{ |
| 27 | Value1scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value1.: config.Value1scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/Config#Value1., |
| 28 | Value2scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value2.: config.Value2scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/Config#Value2., |
| 29 | Value3scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value3.: config.Value3scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/Config#Value3., |
| 30 | } |
| 31 | |
| 32 | if params != nil { |
| 33 | if value, found := (*params)["value1"]; found { |
| 34 | payload.Value1scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value1. = value |
| 35 | } |
| 36 | |
| 37 | if value, found := (*params)["value2"]; found { |
| 38 | payload.Value2scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value2. = value |
| 39 | } |
| 40 | |
| 41 | if value, found := (*params)["value3"]; found { |
| 42 | payload.Value3scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value3. = value |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | switch config.UseMessageAsValuescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/Config#UseMessageAsValue. { |
| 47 | case ValueFieldOnescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/ValueFieldOne.: |
| 48 | payload.Value1scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value1. = message |
| 49 | case ValueFieldTwoscip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/ValueFieldTwo.: |
| 50 | payload.Value2scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value2. = message |
| 51 | case ValueFieldThreescip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/ValueFieldThree.: |
| 52 | payload.Value3scip-go gomod github.com/nicholas-fedor/shoutrrr . `github.com/nicholas-fedor/shoutrrr/pkg/services/push/ifttt`/jsonPayload#Value3. = message |
| 53 | } |
| 54 | |
| 55 | jsonBytes, err := jsonscip-go gomod github.com/golang/go/src . `encoding/json`/.Marshalscip-go gomod github.com/golang/go/src . `encoding/json`/Marshal().(payload) |
| 56 | if err != nil { |
| 57 | return nil, fmtscip-go gomod github.com/golang/go/src . fmt/.Errorfscip-go gomod github.com/golang/go/src . fmt/Errorf().("marshaling IFTTT payload to JSON: %w", err) |
| 58 | } |
| 59 | |
| 60 | return jsonBytes, nil |
| 61 | } |