bot

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: AGPL-3.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddChannel

func AddChannel(ctx context.Context, db *gorm.DB, client *slack.Client, p *AddChannelParams) error

AddChannel adds a Slack channel to the database.

func AddMember

func AddMember(ctx context.Context, db *gorm.DB, client *slack.Client, p *AddMemberParams) error

AddMember adds a new member of a Slack channel to the database and begins the onboarding process for them.

func CheckPair

func CheckPair(ctx context.Context, db *gorm.DB, client *slack.Client, p *CheckPairParams) error

CheckPair sends a private group message to a chat-roulette pair to check if they have had a chance to meet during this round of chat-roulette.

func CreateMatches

func CreateMatches(ctx context.Context, db *gorm.DB, client *slack.Client, p *CreateMatchesParams) error

CreateMatches creates matches between active participants for a round of chat-roulette.

func CreatePair

func CreatePair(ctx context.Context, db *gorm.DB, client *slack.Client, p *CreatePairParams) error

CreatePair creates a pairing between 2 matched participants.

func CreateRound

func CreateRound(ctx context.Context, db *gorm.DB, client *slack.Client, p *CreateRoundParams) error

CreateRound adds a new chat roulette round for a Slack channel to the database.

func DeleteChannel

func DeleteChannel(ctx context.Context, db *gorm.DB, client *slack.Client, p *DeleteChannelParams) error

DeleteChannel deletes a Slack channel from the database.

func DeleteMember

func DeleteMember(ctx context.Context, db *gorm.DB, client *slack.Client, p *DeleteMemberParams) error

DeleteMember deletes a member who has left a Slack channel from the database.

func EndRound

func EndRound(ctx context.Context, db *gorm.DB, client *slack.Client, p *EndRoundParams) error

EndRound completes a running chat-roulette round for a Slack channel.

func ExecJob

func ExecJob[T any](ctx context.Context, db *gorm.DB, client *slack.Client, job *models.Job, f JobFunc[T]) error

ExecJob is a generic function for executing job functions.

func FirstChatRouletteRound

func FirstChatRouletteRound(t time.Time, weekday string, hour int) time.Time

FirstChatRouletteRound returns the timestamp of the first chat roulette round.

func GetBotUserID

func GetBotUserID(ctx context.Context, client *slack.Client) (string, error)

GetBotUserID uses Slack's auth.test API method to retrieve the UserID of the chat-roulette bot

func GreetMember

func GreetMember(ctx context.Context, db *gorm.DB, client *slack.Client, p *GreetMemberParams) error

GreetMember greets a new member of a Slack channel with a welcome message.

func HandleAppHomeEvent

func HandleAppHomeEvent(ctx context.Context, client *slack.Client, db *gorm.DB, p *AppHomeParams) error

HandleAppHomeEvent handles the app_home_opened event and publishes the view for the App Home.

func HandleCheckPairButtons

func HandleCheckPairButtons(ctx context.Context, client *http.Client, db *gorm.DB, interaction *slack.InteractionCallback) error

HandleCheckPairButtons processes the webhook sent by Slack when a user clicks on the button in the message sent by the CHECK_PAIR job confirming if they have had a chance to meet the participant that they were paired with in this round of chat roulette. A response is sent overwriting the button in the original message, so that it cannot be clicked multiple times. This interaction contains multiple buttons, so we do need to parse the action. An UPDATE_MATCH job is then queued to modify the "has_met" column for the match in the database.

func HandleGreetMemberButton

func HandleGreetMemberButton(ctx context.Context, client *slack.Client, interaction *slack.InteractionCallback) error

HandleGreetMemberButton processes the webhook sent by Slack when a user clicks on the button in the GREET_MESSAGE job confirming that they wish to participate in chat roulette. A modal is opened to collect onboarding information and upon submission, a response is sent to Slack overwriting the button in the original message, so that it cannot be clicked multiple times. Since this interaction only contains a single button, we do not need to parse the action.

func IsUserABot

func IsUserABot(ctx context.Context, client *slack.Client, userID string) (bool, error)

IsUserABot uses Slack's users.info API method to check if the given user is actually a bot.

func NextChatRouletteRound

func NextChatRouletteRound(t time.Time, interval models.IntervalEnum) time.Time

NextChatRouletteRound returns the timestamp of the next chat roulette round.

func NotifyPair

func NotifyPair(ctx context.Context, db *gorm.DB, client *slack.Client, p *NotifyPairParams) error

NotifyPair notifies a pair of chat-roulette participants that they have been matched for this round of chat-roulette.

func PairParticipants

func PairParticipants(pairings []ChatRoulettePair) map[string]string

PairParticipants takes a list of potential matches for a round of chat roulette and returns the pairings of participants.

func QueueAddChannelJob

func QueueAddChannelJob(ctx context.Context, db *gorm.DB, p *AddChannelParams) error

QueueAddChannelJob adds a new ADD_CHANNEL job to the queue

func QueueAddMemberJob

func QueueAddMemberJob(ctx context.Context, db *gorm.DB, p *AddMemberParams) error

QueueAddChannelJob adds a new ADD_MEMBER job to the queue.

func QueueCheckPairJob

func QueueCheckPairJob(ctx context.Context, db *gorm.DB, p *CheckPairParams) error

QueueCheckPairJob adds a new CHECK_PAIR job to the queue.

func QueueCreateMatchesJob

func QueueCreateMatchesJob(ctx context.Context, db *gorm.DB, p *CreateMatchesParams) error

QueueCreateMatchesJob adds a new CREATE_MATCHES job to the queue.

func QueueCreatePairJob

func QueueCreatePairJob(ctx context.Context, db *gorm.DB, p *CreatePairParams) error

QueueCreatePairJob adds a new CREATE_PAIR job to the queue.

func QueueCreateRoundJob

func QueueCreateRoundJob(ctx context.Context, db *gorm.DB, p *CreateRoundParams) error

QueueCreateRoundJob adds a new CREATE_ROUND job to the queue.

func QueueDeleteChannelJob

func QueueDeleteChannelJob(ctx context.Context, db *gorm.DB, p *DeleteChannelParams) error

DeleteChannelJob adds a new DELETE_CHANNEL job to the queue.

func QueueDeleteMemberJob

func QueueDeleteMemberJob(ctx context.Context, db *gorm.DB, p *DeleteMemberParams) error

QueueDeleteMemberJob adds a new DELETE_MEMBER job to the queue.

func QueueEndRoundJob

func QueueEndRoundJob(ctx context.Context, db *gorm.DB, p *EndRoundParams) error

QueueEndRoundJob adds a new END_ROUND job to the queue.

func QueueGreetMemberJob

func QueueGreetMemberJob(ctx context.Context, db *gorm.DB, p *GreetMemberParams) error

QueueGreetMemberJob adds a new GREET_MEMBER job to the queue.

func QueueJob

func QueueJob[T any](ctx context.Context, db *gorm.DB, gJob models.GenericJob[T]) error

QueueJob is a generic function for adding a background job to the database job queue.

func QueueNotifyPairJob

func QueueNotifyPairJob(ctx context.Context, db *gorm.DB, p *NotifyPairParams) error

QueueNotifyPairJob adds a new NOTIFY_PAIR job to the queue.

func QueueReportStatsJob

func QueueReportStatsJob(ctx context.Context, db *gorm.DB, p *ReportStatsParams) error

QueueReportStatsJob adds a new REPORT_STATS job to the queue.

func QueueSyncChannelsJob

func QueueSyncChannelsJob(ctx context.Context, db *gorm.DB, p *SyncChannelsParams) error

QueueSyncChannelsJob adds a new SYNC_CHANNELS job to the queue.

func QueueSyncMembersJob

func QueueSyncMembersJob(ctx context.Context, db *gorm.DB, p *SyncMembersParams) error

QueueSyncMembersJob adds a new SYNC_MEMBERS job to the queue.

func QueueUpdateChannelJob

func QueueUpdateChannelJob(ctx context.Context, db *gorm.DB, p *UpdateChannelParams) error

UpdateChannelJob adds a new UPDATE_CHANNEL job to the queue.

func QueueUpdateMatchJob

func QueueUpdateMatchJob(ctx context.Context, db *gorm.DB, p *UpdateMatchParams) error

QueueUpdateMatchJob adds a new UPDATE_MATCH job to the queue.

func QueueUpdateMemberJob

func QueueUpdateMemberJob(ctx context.Context, db *gorm.DB, p *UpdateMemberParams) error

QueueUpdateMemberJob adds a new UPDATE_MEMBER job to the queue.

func RenderOnboardingCalendlyView

func RenderOnboardingCalendlyView(ctx context.Context, interaction *slack.InteractionCallback, baseURL string) ([]byte, error)

RenderOnboardingCalendlyView renders the view template for collecting a new member's calendly link.

func RenderOnboardingLocationView

func RenderOnboardingLocationView(ctx context.Context, interaction *slack.InteractionCallback, baseURL string) ([]byte, error)

RenderOnboardingLocationView renders the view template for collecting a new member's location data.

func RenderOnboardingProfileView

func RenderOnboardingProfileView(ctx context.Context, interaction *slack.InteractionCallback, baseURL string) ([]byte, error)

RenderOnboardingProfileView renders the view template for collecting a new member's profile info.

func RenderOnboardingTimezoneView

func RenderOnboardingTimezoneView(ctx context.Context, interaction *slack.InteractionCallback, baseURL string) ([]byte, error)

RenderOnboardingTimezoneView renders the view template for collecting a new member's timezone data.

func ReportStats

func ReportStats(ctx context.Context, db *gorm.DB, client *slack.Client, p *ReportStatsParams) error

ReportStats messages a Slack channel with the stats for the last round of chat-roulette.

func RespondGreetMemberWebhook

func RespondGreetMemberWebhook(ctx context.Context, client *http.Client, interaction *slack.InteractionCallback) error

RespondGreetMemberWebhook responds to the Slack webhook received when the "Opt In" button in the GREET_MEMBER message is clicked. The original message is updated to overwrite the button, so that it cannot be clicked multiple times.

func SyncChannels

func SyncChannels(ctx context.Context, db *gorm.DB, client *slack.Client, p *SyncChannelsParams) error

SyncChannels ensures that there is no discrepancy between the Slack channels in the database and the Slack channels that the bot is a member of.

func SyncMembers

func SyncMembers(ctx context.Context, db *gorm.DB, client *slack.Client, p *SyncMembersParams) error

SyncMembers ensures that there is no discrepancy between the members of Slack channels in the database and in Slack.

func UpdateChannel

func UpdateChannel(ctx context.Context, db *gorm.DB, client *slack.Client, p *UpdateChannelParams) error

UpdateChannel updates the settings for a chat-roulette enabled Slack channel.

func UpdateMatch

func UpdateMatch(ctx context.Context, db *gorm.DB, client *slack.Client, p *UpdateMatchParams) error

UpdateMatch updates the has_met status for a match at the end of a chat-roulette round.

func UpdateMember

func UpdateMember(ctx context.Context, db *gorm.DB, client *slack.Client, p *UpdateMemberParams) error

UpdateMember updates the participation status for a member of a Slack channel.

func UpsertMemberCalendlyLink(ctx context.Context, db *gorm.DB, interaction *slack.InteractionCallback) error

UpsertMemberCalendlyLink collects a new member's Calendly link during the onboarding flow and updates it in the database.

func UpsertMemberLocationInfo

func UpsertMemberLocationInfo(ctx context.Context, db *gorm.DB, interaction *slack.InteractionCallback) error

UpsertMemberLocationInfo collects a new member's location info during the onboarding flow and updates it in the database.

func UpsertMemberProfileInfo

func UpsertMemberProfileInfo(ctx context.Context, db *gorm.DB, interaction *slack.InteractionCallback) error

UpsertMemberProfileInfo collects a new member's profile info during the onboarding flow and updates it in the database.

func UpsertMemberTimezoneInfo

func UpsertMemberTimezoneInfo(ctx context.Context, db *gorm.DB, interaction *slack.InteractionCallback) error

UpsertMemberTimezoneInfo collects a new member's timezone info during the onboarding flow and updates it in the database.

func ValidateMemberCalendlyLink(ctx context.Context, link string) error

ValidateMemberCalendlyLink validates that the user-provided Calendly link is a valid.

Note: providing a Calendly link is optional.

func ValidateMemberProfileInfo

func ValidateMemberProfileInfo(ctx context.Context, interaction *slack.InteractionCallback) error

ValidateMemberProfileInfo validates that the user provided social profile link is a valid URL for the supported social profile types.

Types

type AddChannelParams

type AddChannelParams struct {
	ChannelID string    `json:"channel_id"`
	Invitor   string    `json:"invitor"`
	Interval  string    `json:"interval"`
	Weekday   string    `json:"weekday"`
	Hour      int       `json:"hour"`
	NextRound time.Time `json:"next_round"`
}

AddChannelParams are the parameters for the ADD_CHANNEL job.

type AddMemberParams

type AddMemberParams struct {
	ChannelID string `json:"channel_id"`
	UserID    string `json:"user_id"`
}

AddMemberParams are the parameters for the ADD_MEMBER job.

type AppHomeParams

type AppHomeParams struct {
	BotUserID string
	URL       string
	UserID    string
	View      slack.View
}

AppHomeParams is the parameters for handling app_home_opened events

type ChatRoulettePair

type ChatRoulettePair struct {
	Participant string
	Partner     string
}

ChatRoulettePair is a pair of participants for chat-roulette

type CheckPairParams

type CheckPairParams struct {
	ChannelID   string    `json:"channel_id"`
	NextRound   time.Time `json:"next_round"`
	MatchID     int32     `json:"match_id"`
	Participant string    `json:"participant"`
	Partner     string    `json:"partner"`
	MpimID      string    `json:"mpim_id"`
}

CheckPairParams are the parameters for the CHECK_PAIR job.

type CreateMatchesParams

type CreateMatchesParams struct {
	ChannelID string `json:"channel_id"`
	RoundID   int32  `json:"round_id"`
}

CreateMatchesParams are the parameters for the CREATE_MATCHES job.

type CreatePairParams

type CreatePairParams struct {
	ChannelID   string `json:"channel_id"`
	MatchID     int32  `json:"match_id"`
	Participant string `json:"participant"`
	Partner     string `json:"partner"`
}

CreatePairParams are the parameters for the CREATE_PAIR job.

type CreateRoundParams

type CreateRoundParams struct {
	ChannelID string    `json:"channel_id"`
	NextRound time.Time `json:"next_round"`
	Interval  string
}

CreateRoundParams are the parameters for the CREATE_ROUND job.

type DeleteChannelParams

type DeleteChannelParams struct {
	ChannelID string `json:"channel_id"`
}

DeleteChannelParams are the parameters for the DELETE_CHANNEL job.

type DeleteMemberParams

type DeleteMemberParams struct {
	ChannelID string `json:"channel_id"`
	UserID    string `json:"user_id"`
}

DeleteMemberParams are the parameters for the DELETE_MEMBER job.

type EndRoundParams

type EndRoundParams struct {
	ChannelID string    `json:"channel_id"`
	NextRound time.Time `json:"next_round"`
}

EndRoundParams are the parameters for the END_ROUND job.

type GreetMemberParams

type GreetMemberParams struct {
	ChannelID string `json:"channel_id"`
	UserID    string `json:"user_id"`
}

GreetMemberParams are the parameters for the GREET_MEMBER job.

type JobFunc

type JobFunc[T any] func(ctx context.Context, db *gorm.DB, client *slack.Client, p *T) error

JobFunc is the function signature for all job functions.

type NotifyPairParams

type NotifyPairParams struct {
	ChannelID   string `json:"channel_id"`
	MatchID     int32  `json:"match_id"`
	Participant string `json:"participant"`
	Partner     string `json:"partner"`
}

NotifyPairParams are the parameters for the NOTIFY_PAIR job.

type ReportStatsParams

type ReportStatsParams struct {
	ChannelID string    `json:"channel_id"`
	RoundID   int32     `json:"round_id"`
	NextRound time.Time `json:"next_round"`
}

ReportStatsParams are the parameters for the REPORT_STATS job.

type SyncChannelsParams

type SyncChannelsParams struct {
	BotUserID          string                    `json:"bot_user_id"`
	ChatRouletteConfig config.ChatRouletteConfig `json:"config"`
}

SyncChannelsParams are the parameters for SYNC_CHANNEL job.

type SyncMembersParams

type SyncMembersParams struct {
	ChannelID string `json:"channel_id"`
}

SyncMembersParams are the parameters for the SYNC_MEMBERS job.

type UpdateChannelParams

type UpdateChannelParams struct {
	ChannelID string    `json:"channel_id"`
	Interval  string    `json:"interval"`
	Weekday   string    `json:"weekday"`
	Hour      int       `json:"hour"`
	NextRound time.Time `json:"next_round"`
}

UpdateChannelParams are the parameters the UPDATE_CHANNEL job.

type UpdateMatchParams

type UpdateMatchParams struct {
	MatchID int32 `json:"match_id"`
	HasMet  bool  `json:"has_met"`
}

UpdateMatchParams are the parameters for the UPDATE_MATCH job.

type UpdateMemberParams

type UpdateMemberParams struct {
	ChannelID    string                    `json:"channel_id"`
	UserID       string                    `json:"user_id"`
	Country      sqlcrypter.EncryptedBytes `json:"country,omitempty"`
	City         sqlcrypter.EncryptedBytes `json:"city,omitempty"`
	Timezone     sqlcrypter.EncryptedBytes `json:"timezone,omitempty"`
	ProfileType  sqlcrypter.EncryptedBytes `json:"profile_type,omitempty"`
	ProfileLink  sqlcrypter.EncryptedBytes `json:"profile_link,omitempty"`
	CalendlyLink sqlcrypter.EncryptedBytes `json:"calendly_link,omitempty"`
	IsActive     bool                      `json:"is_active"`
}

UpdateMemberParams are the parameters for the UPDATE_MEMBER job.

Jump to

Keyboard shortcuts

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