-
Notifications
You must be signed in to change notification settings - Fork 19
/
attachments.go
47 lines (38 loc) · 1.07 KB
/
attachments.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
package flows
import (
"fmt"
"strings"
"github.com/nyaruka/goflow/utils"
)
// Attachment is a media attachment on a message
type Attachment string
// ContentType returns the MIME type of this attachment
func (a Attachment) ContentType() string {
offset := strings.Index(string(a), ":")
if offset >= 0 {
return string(a[:offset])
}
return ""
}
// URL returns the full URL of this attachment
func (a Attachment) URL() string {
offset := strings.Index(string(a), ":")
if offset >= 0 {
return string(a[offset+1:])
}
return string(a)
}
// Resolve resolves the given key when this attachment is referenced in an expression
func (a Attachment) Resolve(key string) interface{} {
switch key {
case "content_type":
return a.ContentType()
case "url":
return a.URL()
}
return fmt.Errorf("No field '%s' on attachment", key)
}
// Default returns the value of this attachment when it is the result of an expression
func (a Attachment) Default() interface{} { return a }
func (a Attachment) String() string { return a.URL() }
var _ utils.VariableResolver = (Attachment)("")