-
Notifications
You must be signed in to change notification settings - Fork 10
/
handler_deskdotcom_out.go
51 lines (41 loc) · 1.16 KB
/
handler_deskdotcom_out.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package deskdotcom
import (
"encoding/json"
"github.com/grokify/chathooks/src/config"
"github.com/grokify/chathooks/src/handlers"
"github.com/grokify/chathooks/src/models"
cc "github.com/grokify/commonchat"
)
const (
DisplayName = "Desk.com"
HandlerKey = "deskdotcom"
MessageDirection = "out"
DocumentationURL = "https://support.desk.com/customer/portal/articles/869334-configuring-webhooks-in-desk-com-apps"
MessageBodyType = models.JSON
)
func NewHandler() handlers.Handler {
return handlers.Handler{MessageBodyType: MessageBodyType, Normalize: Normalize}
}
func Normalize(cfg config.Configuration, bytes []byte) (cc.Message, error) {
ccMsg, err := CcMessageFromBytes(bytes)
if err != nil {
return ccMsg, err
}
iconURL, err := cfg.GetAppIconURL(HandlerKey)
if err == nil {
ccMsg.IconURL = iconURL.String()
}
return ccMsg, nil
}
/*
Example template:
{
"activity":"Case {{case.id}} updated",
"body":"**Case Type**\n{{case.status}} {{case.type}}\n **Subject**\n[{{case.subject}}]({{case.direct_url}})"
}
*/
func CcMessageFromBytes(bytes []byte) (cc.Message, error) {
msg := cc.Message{}
err := json.Unmarshal(bytes, &msg)
return msg, err
}