# slack words finder (EN) ###### tags: `Slack` `Bot` `EN` ## Overview + This bot verifies and matches the messages and files with messages on Slack with a regular expression that has been set up and automatically collect them to a specific channel. + The default triggering emoji is :comet: ## Architecture / Design + Adopt Nedb. + Adopt MVC model. Please refer to `cluster manager`. + Clear the development quality diagnosis corresponding to `cluster manager`. ## Function ### ADD CMD (Set a regular expression.) + How to use this command   1. Write emoji `: comet:` at the beginning. `: comet:`   2. Next, add `add`. `: comet: add`   3. Next, write the regular expression you want to add. `: comet: add / sample / i`   4. Not available for threads. ### REMOVE CMD (Delete the registered regular expression.) + How to use this command   1. Add `: comet:` as the first character. `: comet:`   2. Next, write `: remove:`. `: comet: remove`   3. Next, enter the number of the regular expression you want to delete. `: comet: 0` ### LIST CMD (Lists which channels are collecting messages with which regular expression.) + How to use this command    1. Add `: comet:` as the first character. `: comet:`    2. Next, write `: list:`. `: comet: list` ### WHEN RECEIVE NEW MSG  Invite our bot account to the channel where you want to collect words. ### ADD CMD [Implementation] + Prerequisite + This command is to add tracking target and set regular expression. + This command can be used by all users. + This bot fires when a text, file send event, or message event with attachment is received. + The regular expression of the firing condition is `/ ^: comet :( |) add (|) \ / (. +) \ / (I |) $ / i` + Sequence    1. Get regular expression from `event parameter text sentence`.    2. Save the value obtained in the first sequence using the `Add method` set below in` reg_exp` of ` Nedb`. ### REMOVE CMD [Implementation] + Prerequisite + This command deletes the regular expression. + Can be used by all users. However, it cannot be used in threads. + Fires when a text type message event is received. + The regular expression of the firing condition is `/ ^: comet :( |) remove (|) \ / ([0-9] +) \ / (i |) $ / i` + Sequence    1. Get regular expression from event parameter text sentence.    2. Use `remove method` to delete the value obtained in the first sequence from` reg_exp` in `NeDB`.    3. If it is used in a thread, refer to `ts` of` event Object` and send a message indicating that it cannot be used. ### LIST CMD [Implementation] + Prerequisite + This command lists the registered regular expressions. + Fires when a text type message event is received. + The regular expression of the firing condition is `/ ^: comet :( |) list $ / i` + Sequence    1. Use the `findMethod` set below. ### WHEN RECEIVE NEW MSG [Implementation] + Sequence     1. Get the text parameter of the received event text.     2. Determine whether the text matches all regular expressions in the DB or not.     3. If there is a match, transfer to the text-matched document channel (https: //slackWorkspaceURL/archives/channelID/event.ts set in the environment variable). ## Operation + Expanded to Glitch server. And `Web server` needs to be expanded to allow external access. ## DB model list ### nedb sample document ```jsonld= { "_id": "", "reg_exps":["aaaaaa","bbbbbb","cccccc",....], "channel_id": "C*********" } ``` + ChannelsRegExp Model   + find Method     + Argument       + nedb (nedb Object)       + ch (channel_id String)     + The contents of this method       1. If the argument `ch` is not set,` {channel: ch} `is output as the return value.       2. Based on the argument `ch`, retrieve the document from` NeDB`.       3. If the argument `ch` exists,` {channel: ch} `is output as the return value.   + add Method     + Argument       + nedb (Object)       + regExp (regExp)       + ch (channel_id String)     + The contents of this method       1. Based on the argument `ch`, retrieve the relevant document from` NeDB`.       2. If there is no matching `ch` when searching in the first sequence, create the` ch` document.       3. If the result of the first sequence and the `reg_exps` array that is the parameter of the corresponding document are retrieved, and the argument` regExp` exists inside the `reg_exps` array,` {'message': 'This RegExp is already existed' , 'regExp': 'Received reg_exp', 'channel': ch} `is output as a return value.       4. Take the result of the first sequence and the `reg_exps` array that is the parameter of the corresponding document, and if the argument` regExp` does not exist inside the `reg_exps` array, add the regular expression to` NeDB`.       5. When all the sequences are finished, output the return value with `{'message': 'This method is completed', 'regExp': 'Received reg_exps', 'channel': ch}`.    + remove Method     + Argument       + nedb (Object)       + regExp Index (Number)       + ch (channel_id String)     + The contents of this method       1. Based on the argument `ch`, retrieve the relevant document from` NeDB`.       2. If the result of the first sequence and the `reg_exps` array that is the parameter of the corresponding document are retrieved and the argument` regExp` does not exist inside the `reg_exps` array,` {message: "Cannot find this RegExp", regExp: "Received reg_exp", channel: "ch"} `is output as a return value.       3. Take the result of the first sequence and the `reg_exps` array that is the parameter of the corresponding document, and if the argument` regExp` exists inside the `reg_exps` array, remove the regular expression from` NeDB`.       4. When all sequences are completed, the return value is output as `{ message: "The remove method is completed", reg_exp: "received reg_exp", channel: "ch" }` to the message. ## List of environment variables + HOST string + PORT integer + EMOJI string + SYSTEM_NAME string (read from package.json) + SLACK_BOT_TOKEN string + SLACK_BOT_ID string