Matterbridge is optional and can appear many times
This commit is contained in:
parent
94a47b2962
commit
15f6e8bc24
|
@ -43,7 +43,7 @@ type AppConfig struct {
|
|||
DisarmCallbackUrls []string `yaml:"disarm-callback-urls"`
|
||||
AlarmCallbackUrls []string `yaml:"alarm-callback-urls"`
|
||||
WriteMemoryProfile bool `yaml:"write-memory-profile"`
|
||||
Matterbridge MatterbridgeConfig `yaml:"matterbridge"`
|
||||
Matterbridge []MatterbridgeConfig `yaml:"matterbridge"`
|
||||
}
|
||||
|
||||
func (m *SatelChangeType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||
|
|
|
@ -32,6 +32,15 @@ disarm-callback-urls:
|
|||
alarm-callback-urls:
|
||||
- "test alarm callback url"
|
||||
- "second test alarm callback url"
|
||||
matterbridge:
|
||||
- uri: test_uri_1
|
||||
token: test_token_1
|
||||
gateway: test_gateway_1
|
||||
username: test_username_1
|
||||
- uri: test_uri_2
|
||||
token: test_token_2
|
||||
gateway: test_gateway_2
|
||||
username: test_username_2
|
||||
`
|
||||
|
||||
func TestParseYamlConfig(t *testing.T) {
|
||||
|
@ -47,4 +56,13 @@ func TestParseYamlConfig(t *testing.T) {
|
|||
a.ElementsMatch([]string{"test arm callback url", "second test arm callback url"}, actualConfig.ArmCallbackUrls)
|
||||
a.ElementsMatch([]string{"test disarm callback url", "second test disarm callback url"}, actualConfig.DisarmCallbackUrls)
|
||||
a.ElementsMatch([]string{"test alarm callback url", "second test alarm callback url"}, actualConfig.AlarmCallbackUrls)
|
||||
|
||||
a.Equal(actualConfig.Matterbridge[0].URI, "test_uri_1")
|
||||
a.Equal(actualConfig.Matterbridge[0].Token, "test_token_1")
|
||||
a.Equal(actualConfig.Matterbridge[0].Gateway, "test_gateway_1")
|
||||
a.Equal(actualConfig.Matterbridge[0].Username, "test_username_1")
|
||||
a.Equal(actualConfig.Matterbridge[1].URI, "test_uri_2")
|
||||
a.Equal(actualConfig.Matterbridge[1].Token, "test_token_2")
|
||||
a.Equal(actualConfig.Matterbridge[1].Gateway, "test_gateway_2")
|
||||
a.Equal(actualConfig.Matterbridge[1].Username, "test_username_2")
|
||||
}
|
||||
|
|
|
@ -126,23 +126,25 @@ func SendToMatterbridge(events <-chan GenericMessage, s SatelNameGetter, config
|
|||
defer wg.Done()
|
||||
for e := range events {
|
||||
returnEvents <- e
|
||||
for _, matterbridgeConfig := range config.Matterbridge {
|
||||
body, err := json.Marshal(MatterbridgeMessage{
|
||||
Text: e.Format(tpl, s, logger),
|
||||
Username: config.Matterbridge.Username,
|
||||
Gateway: config.Matterbridge.Gateway,
|
||||
Username: matterbridgeConfig.Username,
|
||||
Gateway: matterbridgeConfig.Gateway,
|
||||
})
|
||||
if err != nil {
|
||||
logger.Fatal("Could not marshal a JSON message: ", err)
|
||||
}
|
||||
req, err := http.NewRequest(http.MethodPost, config.Matterbridge.URI, bytes.NewBuffer(body))
|
||||
req.Header["Authorization"] = []string{fmt.Sprint("Bearer ", config.Matterbridge.Token)}
|
||||
req, err := http.NewRequest(http.MethodPost, matterbridgeConfig.URI, bytes.NewBuffer(body))
|
||||
req.Header["Authorization"] = []string{fmt.Sprint("Bearer ", matterbridgeConfig.Token)}
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
logger.Print("Could not POST ", config.Matterbridge.URI, ": ", err)
|
||||
logger.Print("Could not POST ", matterbridgeConfig.URI, ": ", err)
|
||||
return
|
||||
}
|
||||
logger.Print("Notified via Matterbridge with result ", res.StatusCode)
|
||||
}
|
||||
}
|
||||
close(returnEvents)
|
||||
}()
|
||||
|
||||
|
|
Loading…
Reference in New Issue