mparser

package
v0.0.0-...-5fb48e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 4, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package mparser parses the text from a Slack message, identifying user, group, and channel mentions. This package also supports stripping those mentions from the message, to allow for easier command processing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Join

func Join(mentions []Mention, sep string) string

Join takes a slice of mentions, and joins them using the sep.

Types

type Mention

type Mention struct {
	Type  Type
	ID    string
	Label string
}

Mention represents a Slack message mention. This could be mentioning a user, a group, or special things like @here, @channel, and @everyone.

If Type is TypeUser or TypeGroup, the ID field will be the ID of the user or group that was mentioned. If the Type is TypeHere, TypeChannel, or TypeEveryone, the ID is the channel the message was sent in.

If the Type is TypeChannelRef, it's someone mentioning a channel in the message, and may include a Label. There is no guarantee this will be set.

func Parse

func Parse(message, channelID string) ([]Mention, [][]int)

Parse takes the message text, and the channel ID where the message was sent, and parses the mentions in the message. This returns the list of mentions, and the start/end index of each mention to allow you to locate them.

For @here, @channel, and @everyone the Mention.ID is set to the channelID.

func ParseAndSplice

func ParseAndSplice(message, channelID string) (string, []Mention)

ParseAndSplice calls Parse(), and uses the start/end index of each mention to remove it from the message and return the resulting string. Please see the Parse() documentation for more information on parsing.

func (Mention) MarshalText

func (m Mention) MarshalText() ([]byte, error)

MarshalText satisfies the encoding.TextMarshaler interface.

func (Mention) String

func (m Mention) String() string

type Type

type Type uint8

Type is a faux-enum for describing whether it was a user or group mention.

const (
	// TypeUser represents a user mention.
	TypeUser Type = 1 << iota

	// TypeGroup represents a workspace group mention.
	TypeGroup

	// TypeHere is for @here mentions. If this Type is used, the
	// Mention.ID will be the channel's ID.
	TypeHere

	// TypeChannel is for @channel mentions. If this Type is used, the
	// Mention.ID will be the channel's ID.
	TypeChannel

	// TypeEveryone is for @everyone metnions. If this Type is used, the
	// Mention.ID will be the channel's ID.
	TypeEveryone

	// TypeChannelRef is a reference to another channel in a message, like if a
	// user were to type "join #general".
	TypeChannelRef
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL