github.com/grokify/go-ringcentral-client@v0.3.31/office/v1/examples/glip/glip_post_attachment/glip_post_attachment.go (about) 1 package main 2 3 import ( 4 "context" 5 "fmt" 6 "os" 7 "time" 8 9 "github.com/grokify/mogo/fmt/fmtutil" 10 11 rc "github.com/grokify/go-ringcentral-client/office/v1/client" 12 rcu "github.com/grokify/go-ringcentral-client/office/v1/util" 13 ) 14 15 const ( 16 envPrefix = "RINGCENTRAL_" 17 ) 18 19 func getDemoMessage() rc.GlipCreatePost { 20 return rc.GlipCreatePost{ 21 Text: "Body of the post", 22 Attachments: []rc.GlipMessageAttachmentInfoRequest{ 23 { 24 Type: "Card", 25 Title: "Attachment Title", 26 Color: "#00ff2a", 27 Author: rc.GlipMessageAttachmentAuthorInfo{ 28 Name: "Author Name", 29 Uri: "https://example.com/author_link", 30 IconUri: "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fd/000080_Navy_Blue_Square.svg/1200px-000080_Navy_Blue_Square.svg.png", 31 }, 32 Text: "Attachment text", 33 Intro: "Attachment intro appears before the attachment block", 34 ImageUri: "https://media3.giphy.com/media/l4FssTixISsPStXRC/giphy.gif", 35 ThumbnailUri: "http://clipart-library.com/img/1415947.jpg", 36 Fallback: "Attachment fallback text", 37 Fields: []rc.GlipMessageAttachmentFieldsInfo{ 38 { 39 Title: "Field 1", 40 Value: "A short field", 41 Style: "Short", 42 }, 43 { 44 Title: "Field 2", 45 Value: "This is [a linked short field](https://example.com)", 46 Style: "Short", 47 }, 48 { 49 Title: "Field 3", 50 Value: "A long, full-width field with *formatting* and [a link](https://example.com)", 51 Style: "Long", 52 }, 53 }, 54 Footnote: rc.GlipMessageAttachmentFootnoteInfo{ 55 Text: "Attachment footer and timestamp", 56 IconUri: "http://www.iconsdb.com/icons/preview/red/square-ios-app-xxl.png", 57 Time: time.Now(), 58 }, 59 }, 60 }, 61 } 62 } 63 64 func getDemoMessageSalesforce() rc.GlipCreatePost { 65 return rc.GlipCreatePost{ 66 Text: "**Top Opportunities**\n\nFull report: https://my.salesforce.com/00O80000007MOgS", 67 Attachments: []rc.GlipMessageAttachmentInfoRequest{ 68 { 69 Type: "Card", 70 Color: "#00ff2a", 71 Fallback: "Attachment fallback text", 72 Fields: []rc.GlipMessageAttachmentFieldsInfo{ 73 { 74 Title: "Opportunity", 75 Value: "[Electric Company of America (0038000004OrS7y)](https://example.com)", 76 Style: "Short"}, 77 { 78 Title: "Owner", 79 Value: "Matthew West", 80 Style: "Short"}, 81 { 82 Title: "Stage", 83 Value: "Contract Negotiation", 84 Style: "Short"}, 85 { 86 Title: "Close Date", 87 Value: "2017-12-20", 88 Style: "Short"}, 89 { 90 Title: "Amount", 91 Value: "$150,000", 92 Style: "Short"}, 93 { 94 Title: "Probability", 95 Value: "95%", 96 Style: "Short"}, 97 }, 98 }, 99 { 100 Type: "Card", 101 Color: "#dfdd13", 102 Fallback: "Attachment fallback text", 103 Fields: []rc.GlipMessageAttachmentFieldsInfo{ 104 { 105 Title: "Opportunity", 106 Value: "[Eureka Oil and Gas (0038000001MgG2z)](https://example.com)", 107 Style: "Short"}, 108 { 109 Title: "Owner", 110 Value: "Alice Collins", 111 Style: "Short"}, 112 { 113 Title: "Stage", 114 Value: "Proposal/Quote", 115 Style: "Short"}, 116 { 117 Title: "Close Date", 118 Value: "2017-09-20", 119 Style: "Short"}, 120 { 121 Title: "Amount", 122 Value: "$750,000", 123 Style: "Short"}, 124 { 125 Title: "Probability", 126 Value: "70%", 127 Style: "Short"}, 128 { 129 Title: "Field 1", 130 Value: "A short field", 131 Style: "Short", 132 }, 133 }, 134 }, 135 { 136 Type: "Card", 137 Color: "#ff0000", 138 Fallback: "Attachment fallback text", 139 Fields: []rc.GlipMessageAttachmentFieldsInfo{ 140 { 141 Title: "Opportunity", 142 Value: "[Pacfic Restaurants (0038000004WhM4a)](https://example.com)", 143 Style: "Short"}, 144 { 145 Title: "Owner", 146 Value: "Justin Lyons", 147 Style: "Short"}, 148 { 149 Title: "Stage", 150 Value: "Discovery", 151 Style: "Short"}, 152 { 153 Title: "Close Date", 154 Value: "2017-09-20", 155 Style: "Short"}, 156 { 157 Title: "Amount", 158 Value: "$500,000", 159 Style: "Short"}, 160 { 161 Title: "Probability", 162 Value: "30%", 163 Style: "Short"}, 164 }, 165 }, 166 }, 167 } 168 } 169 170 func main() { 171 err := rcu.LoadEnv() 172 if err != nil { 173 panic(err) 174 } 175 groupId := os.Getenv("GLIP_POST_GROUP_ID") 176 177 apiClient, err := rcu.NewApiClientPasswordEnv(envPrefix) 178 if err != nil { 179 panic(err) 180 } 181 182 msgs := []rc.GlipCreatePost{} 183 msgs = append(msgs, getDemoMessage()) 184 msgs = append(msgs, getDemoMessageSalesforce()) 185 186 fmtutil.PrintJSON(msgs) 187 188 for _, msg := range msgs { 189 info, resp, err := apiClient.GlipApi.CreatePost(context.Background(), groupId, msg) 190 if err != nil { 191 panic(err) 192 } else if resp.StatusCode > 299 { 193 panic(fmt.Errorf("API Status %v", resp.StatusCode)) 194 } 195 fmtutil.PrintJSON(info) 196 } 197 fmt.Println("DONE") 198 }