Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjusting slack event data scheme to not use authed_users. Fixes #96 #97

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions bot/handle-slack-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ const commandResponse = (
messageLists.map((message) =>
message.text
? slackRequest.post('chat.postEphemeral', team._token, {
...message,
channel: event.channel,
thread_ts: event.thread_ts,
})
...message,
channel: event.channel,
thread_ts: event.thread_ts,
})
: Promise.resolve()
)
)
Expand All @@ -55,7 +55,7 @@ const commandResponse = (
.then(() => 'sent command response')

const handleSlackMessage = async (
{ team_id, bot_id }: { team_id: string; bot_id: string },
{ team_id, bot_id }: { team_id: string; bot_id?: string },
event: {
type: 'app_uninstalled' | 'message' | 'app_home_opened'
channel_type: 'app_home' | 'im'
Expand Down Expand Up @@ -127,11 +127,11 @@ const handleSlackMessage = async (
messageBuilder(team, event.user, times).map(({ user, text }) =>
text
? slackRequest.post('chat.postEphemeral', team._token, {
channel: event.channel,
user,
text,
thread_ts: event.thread_ts,
})
channel: event.channel,
user,
text,
thread_ts: event.thread_ts,
})
: Promise.resolve()
)
).then(() => 'time translations sent')
Expand All @@ -156,14 +156,26 @@ export default async function (body: {
channel: string
thread_ts: string
}
authed_users: string[]
authorizations: {
enterprise_id?: string
team_id: string
user_id: string
is_bot: boolean
is_enterpries_install: boolean
}[]
}) {
if (body.type !== 'event_callback' || !body.event) {
return 'not sure how to handle that...'
}

const { event, authed_users } = body
const bot_id = authed_users[0]
const { event, authorizations } = body
const bot_id = (() => {
if (authorizations.length > 0) {
return authorizations[0]['user_id']
} else {
return undefined;
}
})()

if (event.type === 'app_uninstalled') {
return handleUninstall(body)
Expand Down
Loading