I am building a custom app for integrating our ERP software with Mattermost ahead of deployment to my company. I have gotten messages returning as I expect on mentioned code words. For example order #9999 returns basic details of that order back to the channel that ‘order #9999’ is mentioned in. I want to format this return data as a formatted Message Attachment. I am finding it impossible to understand how to do this. I started with the Go Bot sample project and built upon that. I would appreciate some guidance. Thanks!
Hi @earlgrei! Apologies for the late reply and thank you for reaching out.
Would you have a link to the project you are using (I just want to make sure I’m looking at the right one)?
@amy.blais I was able to get it figured out with the help of @hmhealey and @jwilander over in the pre-release MM server. Code sample is included.
I was using this sample project to get started. https://github.com/mattermost/mattermost-bot-sample-golang
post := &model.Post{
Message: "message",
ChannelId: replyToChannel,
Props: map[string]interface{}{
"attachments": []model.SlackAttachment{
{
Color: "#7800FF",
Pretext: "Some text here",
Text: "This is the text of the attachment. It should appear just above the image",
ThumbURL: "https://slack.global.ssl.fastly.net/7bf4/img/services/jenkins-ci_128.png",
Title: "A slack attachment",
TitleLink: "https://www.google.com",
},
},
},
}
1 Like
To format the return data as a Message Attachment, you can use the model.SlackAttachment
struct in your Go Bot code. Here’s a basic example:
attachment := &model.SlackAttachment{
Title: "Order Details",
Text: "Here are the details for order #9999",
Fields: []*model.SlackAttachmentField{
{
Title: "Order ID",
Value: "9999",
Short: true,
},
{
Title: "Status",
Value: "Processing",
Short: true,
},
},
}
post := &model.Post{
ChannelId: channelID,
Message: "Order Details:",
Props: map[string]interface{}{
"attachments": []*model.SlackAttachment{attachment},
},
}
_, resp := client.CreatePost(post)
if resp.Error != nil {
// Handle error
}
Replace channelID
with the actual channel ID. This should help you present your ERP software data in a structured and readable format.