{"id":21091147,"url":"https://github.com/manikmaity/message-slack-backend","last_synced_at":"2025-03-14T06:21:43.070Z","repository":{"id":262938574,"uuid":"888826496","full_name":"ManikMaity/Message-Slack-Backend","owner":"ManikMaity","description":null,"archived":false,"fork":false,"pushed_at":"2025-01-20T07:21:24.000Z","size":334,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-27T03:16:40.193Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ManikMaity.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-15T04:36:22.000Z","updated_at":"2025-01-20T07:21:25.000Z","dependencies_parsed_at":"2024-12-04T11:24:30.907Z","dependency_job_id":"6b6d8e7d-d20e-4cd0-8b52-f3af67f41828","html_url":"https://github.com/ManikMaity/Message-Slack-Backend","commit_stats":null,"previous_names":["manikmaity/message-slack-backend"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManikMaity%2FMessage-Slack-Backend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManikMaity%2FMessage-Slack-Backend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManikMaity%2FMessage-Slack-Backend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ManikMaity%2FMessage-Slack-Backend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ManikMaity","download_url":"https://codeload.github.com/ManikMaity/Message-Slack-Backend/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243532786,"owners_count":20306209,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T21:43:46.541Z","updated_at":"2025-03-14T06:21:43.040Z","avatar_url":"https://github.com/ManikMaity.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Slack Backend\n\n#### New npm packages\n\n- `http-status-codes` - This package is used to return status codes for the API responses.\n- `eslint` - eslint is a tool for identifying and reporting on patterns found in JavaScript. [Atricle to Setup](https://medium.com/@sindhujad6/setting-up-eslint-and-prettier-in-a-node-js-project-f2577ee2126f).\n- `prettier` - prettier is a code formatter.\n- `\"simple-import-sort` - This is a pulugin for eslint to sort imports.\n- In production we have two environments, development and production.\n- So we can setup our database according to the environment in db.config.js.\n- [RoboHash](https://robohash.org/) - This is a website which generates avatar images from text for you.\n\n- Add the token to collection variables in postman in script tab beside the Body scrite the following code:\n\n```js\nvar jsonData = pm.response.json()\nvar token = jsonData.data.token\npm.collectionVariables.set('slack_token', token)\n```\n\n- This will add the token to the collection variables so that we can use it in the next request.\n\n### Message model\n\n```js\n\nconst messageSchema = new mongoose.Schema({\n    text: String,\n    user : {\n        type : ObjectId,\n        ref : 'User'\n    },\n    channel : ObjectId,\n    likes : [{\n        user : ObjectId,\n        likeType : String\n    }],\n    replies : [{\n        ObjectId,\n        ref : 'Message'\n    }],\n    seenBy : [{\n        user : {\n            type : ObjectId,\n            ref : 'User'\n        },\n        seenAt : Date\n        seen : Boolean\n    }]\n\n}, {timestamps : true})\n```\n\n\n## Setup nodemailer\n- NodeMailer is a package for sending emails.\n- `npm install nodemailer`\n- [Atricle to Setup](https://medium.com/@y.mehnati_49486/how-to-send-an-email-from-your-gmail-account-with-nodemailer-837bf09a7628)\n- [Create App Password For Gmail Link](https://myaccount.google.com/apppasswords?pli=1\u0026rapt=AEjHL4PjZPv_RFzLvDpJpgNezLLlTZ-eKcC011hXQB6Mh7gjQFn1dLrq76bIrxMqjz4JbJ6YTbapvSKegaX1_YU3qxI-yUuzG_4l33osM5Z6PusG9P2bQyQ)\n\n## How to setup redis queue in project\n- In `Ubuntu terminal` run `redis-server` - This will start the redis server\n- Install `npm install ioredis` and `npm install bull`\n- In `env` file add `RADIS_HOST = localhost` and `REDIS_PORT = 6379`\n- Make a `queues` folder in `src` folder and make a `mail.queue.js` file in that folder\n- Configure the `bull` in `mail.queue.js` file\n```js\nimport Queue from \"bull\";\n\nimport { RADIS_HOST, RADIS_PORT} from \"../config/variables.js\";\n\nexport default new Queue(\"mailQueue\", {\n    redis: {\n        host: RADIS_HOST,\n        port: RADIS_PORT,\n    },\n});\n```\n- To use it make a `producers` folder in `src` and make  a `mailQueue.producer.js` file \n\n```js\nimport mailQueue from \"../queues/mail.queue.js\"\nexport const addEmailToQueue = async (emailData) =\u003e {\n    try {\n        await mailQueue.add(emailData);\n        console.log(\"Email added to queue\");\n    }\n    catch(err){\n        console.log(\"Add email to queue error\", err);\n    }\n}\n```\n- Now we can add mail to queue.\n```js\nexport async function addMemberToWorkSpace (req, res) {\n    // all code \n    const respose = await workspaceRepo.addMemberToWorkspace(\n    workspaceId,\n    memberId,\n    role\n  )\n  addEmailToQueue(createJoinWorkspaceMail(workspace.name, user.email));\n  return respose\n}\n```\n- Now make a comumer for the queue.\n- Make a `processors` folder in `src` and make a `mail.processor.js` file\n```js\nimport transporter from \"../config/mail.config.js\";\nimport mailQueue from \"../queues/mail.queue.js\";\n\nmailQueue.process(async (job) =\u003e {\n    const { emailData } = job.data;\n    try {\n        const respose = await transporter.sendMail(emailData);\n        console.log(\"Email sent successfully\", respose);\n    }\n    catch(err){\n        console.log(\"Email processing error\", err);\n    }\n});\n```\n- Now import the processor in `mailQueue.producer.js`\n```js \n// ./producers/mailQueue.producer.js\nimport \"../processors/mail.processor.js\"\n```\n\n## Web Socket\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanikmaity%2Fmessage-slack-backend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanikmaity%2Fmessage-slack-backend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanikmaity%2Fmessage-slack-backend/lists"}