import './utils/env' ; import { App , LogLevel , subtype , BotMessageEvent , BlockAction } from '@slack/bolt' ; import { isGenericMessageEvent , isMessageItem , } from './utils/helpers' ; const app = new App ( { token : process . env . SLACK_BOT_TOKEN , signingSecret : process . env . SLACK_SIGNING_SECRET , logLevel : LogLevel . DEBUG , } ) ; /**
 * Listening to messages
 */ app . message ( ':wave:' , async ( { message , say } ) => { if ( ! isGenericMessageEvent ( message ) ) return ; await say ( `Hello, <@${ message . user }>` ) ; } ) ; /**
 * Sending messages
 */ app . message ( 'knock knock' , async ( { say } ) => { await say ( '_Who\'s there?_' ) ; } ) ; app . event ( 'reaction_added' , async ( { event , client } ) => { if ( event . reaction === 'calendar' && isMessageItem ( event . item ) ) { await client . chat . postMessage ( { text : 'Pick a reminder date' , channel : event . item . channel , blocks : [ { type : 'section' , text : { type : 'mrkdwn' , text : 'Pick a date for me to remind you' , } , accessory : { type : 'datepicker' , action_id : 'datepicker_remind' , initial_date : '2019-04-28' , placeholder : { type : 'plain_text' , text : 'Select a date' , } , } , } ] , } ) ; } } ) ; /**
 * Listening to events
 */ const welcomeChannelId = 'C12345' ; app . event ( 'team_join' , async ( { event , client , logger } ) => { try { const result = await client . chat . postMessage ( { channel : welcomeChannelId , text : `Welcome to the team, <@${ event . user }>! 🎉 You can introduce yourself in this channel.` , } ) ; logger . info ( result ) ; } catch ( error ) { logger . error ( error ) ; } } ) ; app . message ( subtype ( 'bot_message' ) , async ( { message , logger } ) => { const botMessage = ( message as BotMessageEvent ) ; logger . info ( `The bot user ${ botMessage . user } said ${ botMessage . text }` ) ; } ) ; /**
 * Using the Web API
 */ const whenSeptemberEnds = '1569887999' ; app . message ( 'wake me up' , async ( { message , client , logger } ) => { try { const result = await client . chat . scheduleMessage ( { channel : message . channel , post_at : whenSeptemberEnds , text : 'Summer has come and passed' , } ) ; } catch ( error ) { logger . error ( error ) ; } } ) ; /**
 * Listening to actions
 */ app . action ( 'approve_button' , async ( { ack } ) => { await ack ( ) ; } ) ; app . action < BlockAction > ( { action_id : 'select_user' , block_id : 'assign_ticket' } , async ( { body , client , ack , logger } ) => { await ack ( ) ; try { if ( body . message ) { await client . reactions . add ( { name : 'white_check_mark' , timestamp : body . message ?. ts , channel : body . channel ?. id , } ) ; } } catch ( error ) { logger . error ( error ) ; } } ) ; app . action ( 'approve_button' , async ( { ack , say } ) => { await ack ( ) ; await say ( 'Request approved 👍' ) ; } ) ; ( async ( ) => { await app . start ( Number ( process . env . PORT ) || 3000 ) ; console . log ( '⚡️ Bolt app is running!' ) ; } ) ( ) ;