Skip to content

Commit

Permalink
feat(Mattermost Plugin): Configure notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Dschoordsch committed Feb 20, 2025
1 parent baf76ce commit a33ef66
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 10 deletions.
26 changes: 26 additions & 0 deletions packages/server/graphql/private/mutations/loginMattermost.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import AuthToken from '../../../database/types/AuthToken'
import getKysely from '../../../postgres/getKysely'
import encodeAuthToken from '../../../utils/encodeAuthToken'
import {MutationResolvers} from '../resolverTypes'

const loginMattermost: MutationResolvers['loginMattermost'] = async (
_source,
{email}
) => {
const pg = getKysely()
const user = await pg
.selectFrom('User')
.selectAll()
.where('email', '=', email)
.executeTakeFirstOrThrow()
const {id: userId, tms} = user
const authToken = new AuthToken({sub: userId, tms})

return {
userId,
authToken: encodeAuthToken(authToken),
isNewUser: true
}
}

export default loginMattermost
10 changes: 10 additions & 0 deletions packages/server/graphql/private/typeDefs/Mutation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,16 @@ type Mutation {
samlName: ID!
): UserLogInPayload!

"""
Log in with email from a trusted Mattermost
"""
loginMattermost(
"""
The email of the user
"""
email: Email!
): UserLogInPayload!

"""
Processes recurrence for meetings that should start and end.
"""
Expand Down
17 changes: 17 additions & 0 deletions packages/server/graphql/public/typeDefs/Mutation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,23 @@ type Mutation {
redirectUri: URL
): AddTeamMemberIntegrationAuthPayload!

linkNotificationChannel(
"""
The ID of the auth to link the channel to
"""
authId: ID!

"""
The team to link the channel to
"""
teamId: ID!

"""
The channel to link
"""
channelId: ID!
): LinkNotificationChannelPayload!

"""
Add the transcription bot to the Zoom meeting
"""
Expand Down
26 changes: 16 additions & 10 deletions packages/server/integrations/mattermost/mattermostWebhookHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@ import appOrigin from '../../appOrigin'
import AuthToken from '../../database/types/AuthToken'
import uWSAsyncHandler from '../../graphql/uWSAsyncHandler'
import parseBody from '../../parseBody'
import getKysely from '../../postgres/getKysely'
import encodeAuthToken from '../../utils/encodeAuthToken'
import publishWebhookGQL from '../../utils/publishWebhookGQL'

const MATTERMOST_SECRET = process.env.MATTERMOST_SECRET


const login = async (email: string) => {
const pg = getKysely()
const user = await pg
.selectFrom('User')
.selectAll()
.where('email', '=', email)
.executeTakeFirstOrThrow()
const authToken = new AuthToken({sub: user.id, tms: user.tms})
return encodeAuthToken(authToken)
const query = `
mutation LoginMattermost($email: String!) {
loginMattermost(email: $email) {
error {
message
}
authToken
}
}
`

const loginResult = await publishWebhookGQL<any>(query, {email})
const {error, authToken} = loginResult?.data?.loginMattermost ?? {}
return authToken
}

const mattermostWebhookHandler = uWSAsyncHandler(async (res: HttpResponse, req: HttpRequest) => {
Expand Down

0 comments on commit a33ef66

Please sign in to comment.