Matterbridge is optional and can appear many times
This commit is contained in:
parent
94a47b2962
commit
15f6e8bc24
20
config.go
20
config.go
|
@ -34,16 +34,16 @@ type MatterbridgeConfig struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type AppConfig struct {
|
type AppConfig struct {
|
||||||
SatelAddr string `yaml:"satel-addr"`
|
SatelAddr string `yaml:"satel-addr"`
|
||||||
ChatIds []int64 `yaml:"tg-chat-ids"`
|
ChatIds []int64 `yaml:"tg-chat-ids"`
|
||||||
AllowedTypes []SatelChangeType `yaml:"allowed-types"`
|
AllowedTypes []SatelChangeType `yaml:"allowed-types"`
|
||||||
AllowedIndexes []int `yaml:"allowed-indexes"`
|
AllowedIndexes []int `yaml:"allowed-indexes"`
|
||||||
PoolInterval OwnDuration `yaml:"pool-interval"`
|
PoolInterval OwnDuration `yaml:"pool-interval"`
|
||||||
ArmCallbackUrls []string `yaml:"arm-callback-urls"`
|
ArmCallbackUrls []string `yaml:"arm-callback-urls"`
|
||||||
DisarmCallbackUrls []string `yaml:"disarm-callback-urls"`
|
DisarmCallbackUrls []string `yaml:"disarm-callback-urls"`
|
||||||
AlarmCallbackUrls []string `yaml:"alarm-callback-urls"`
|
AlarmCallbackUrls []string `yaml:"alarm-callback-urls"`
|
||||||
WriteMemoryProfile bool `yaml:"write-memory-profile"`
|
WriteMemoryProfile bool `yaml:"write-memory-profile"`
|
||||||
Matterbridge MatterbridgeConfig `yaml:"matterbridge"`
|
Matterbridge []MatterbridgeConfig `yaml:"matterbridge"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SatelChangeType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (m *SatelChangeType) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
|
|
@ -32,6 +32,15 @@ disarm-callback-urls:
|
||||||
alarm-callback-urls:
|
alarm-callback-urls:
|
||||||
- "test alarm callback url"
|
- "test alarm callback url"
|
||||||
- "second 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) {
|
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 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 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.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,22 +126,24 @@ func SendToMatterbridge(events <-chan GenericMessage, s SatelNameGetter, config
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for e := range events {
|
for e := range events {
|
||||||
returnEvents <- e
|
returnEvents <- e
|
||||||
body, err := json.Marshal(MatterbridgeMessage{
|
for _, matterbridgeConfig := range config.Matterbridge {
|
||||||
Text: e.Format(tpl, s, logger),
|
body, err := json.Marshal(MatterbridgeMessage{
|
||||||
Username: config.Matterbridge.Username,
|
Text: e.Format(tpl, s, logger),
|
||||||
Gateway: config.Matterbridge.Gateway,
|
Username: matterbridgeConfig.Username,
|
||||||
})
|
Gateway: matterbridgeConfig.Gateway,
|
||||||
if err != nil {
|
})
|
||||||
logger.Fatal("Could not marshal a JSON message: ", err)
|
if err != nil {
|
||||||
|
logger.Fatal("Could not marshal a JSON message: ", err)
|
||||||
|
}
|
||||||
|
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 ", matterbridgeConfig.URI, ": ", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
logger.Print("Notified via Matterbridge with result ", res.StatusCode)
|
||||||
}
|
}
|
||||||
req, err := http.NewRequest(http.MethodPost, config.Matterbridge.URI, bytes.NewBuffer(body))
|
|
||||||
req.Header["Authorization"] = []string{fmt.Sprint("Bearer ", config.Matterbridge.Token)}
|
|
||||||
res, err := http.DefaultClient.Do(req)
|
|
||||||
if err != nil {
|
|
||||||
logger.Print("Could not POST ", config.Matterbridge.URI, ": ", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logger.Print("Notified via Matterbridge with result ", res.StatusCode)
|
|
||||||
}
|
}
|
||||||
close(returnEvents)
|
close(returnEvents)
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue