Example #1
0
// This method only parses and processes the attachments,
// all else should be set in the post which is passed
func parseSlackAttachment(post *model.Post, attachments interface{}) {
	post.Type = model.POST_SLACK_ATTACHMENT

	if list, success := attachments.([]interface{}); success {
		for i, aInt := range list {
			attachment := aInt.(map[string]interface{})
			if aText, ok := attachment["text"].(string); ok {
				aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
				attachment["text"] = aText
				list[i] = attachment
			}
			if aText, ok := attachment["pretext"].(string); ok {
				aText = linkWithTextRegex.ReplaceAllString(aText, "[${2}](${1})")
				attachment["pretext"] = aText
				list[i] = attachment
			}
			if fVal, ok := attachment["fields"]; ok {
				if fields, ok := fVal.([]interface{}); ok {
					// parse attachment field links into Markdown format
					for j, fInt := range fields {
						field := fInt.(map[string]interface{})
						if fValue, ok := field["value"].(string); ok {
							fValue = linkWithTextRegex.ReplaceAllString(fValue, "[${2}](${1})")
							field["value"] = fValue
							fields[j] = field
						}
					}
					attachment["fields"] = fields
					list[i] = attachment
				}
			}
		}
		post.AddProp("attachments", list)
	}
}
Example #2
0
func SendEphemeralPost(teamId, userId string, post *model.Post) {
	post.Type = model.POST_EPHEMERAL

	// fill in fields which haven't been specified which have sensible defaults
	if post.Id == "" {
		post.Id = model.NewId()
	}
	if post.CreateAt == 0 {
		post.CreateAt = model.GetMillis()
	}
	if post.Props == nil {
		post.Props = model.StringInterface{}
	}

	message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_EPHEMERAL_MESSAGE, "", post.ChannelId, userId, nil)
	message.Add("post", post.ToJson())

	go Publish(message)
}
Example #3
0
func SendEphemeralPost(teamId, userId string, post *model.Post) {
	post.Type = model.POST_EPHEMERAL

	// fill in fields which haven't been specified which have sensible defaults
	if post.Id == "" {
		post.Id = model.NewId()
	}
	if post.CreateAt == 0 {
		post.CreateAt = model.GetMillis()
	}
	if post.Props == nil {
		post.Props = model.StringInterface{}
	}
	if post.Filenames == nil {
		post.Filenames = []string{}
	}

	message := model.NewMessage(teamId, post.ChannelId, userId, model.ACTION_EPHEMERAL_MESSAGE)
	message.Add("post", post.ToJson())

	PublishAndForget(message)
}