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

Switch Survey to use Strapi Single-Type #17

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@
"url": "https://github.com/strapi-community/strapi-ai-bot/issues"
},
"dependencies": {
"@strapi/plugin-users-permissions": "4.1.8",
"@strapi/provider-upload-aws-s3": "4.1.8",
"@strapi/strapi": "4.1.8",
"@strapi/plugin-color-picker": "4.6.0",
"@strapi/plugin-users-permissions": "4.6.0",
"@strapi/provider-upload-aws-s3": "4.6.0",
"@strapi/strapi": "4.6.0",
"better-sqlite3": "7.5.1",
"pg": "8.7.3"
},
"devDependencies": {},
"license": "MIT",
"engines": {
"node": ">=12.x.x <=16.x.x",
"node": ">=12.x.x <=18.x.x",
"npm": ">=6.0.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"kind": "singleType",
"collectionName": "new_user_surveys",
"info": {
"singularName": "new-user-survey",
"pluralName": "new-user-surveys",
"displayName": "New User Survey",
"description": ""
},
"options": {
"draftAndPublish": false
},
"attributes": {
"embedColor": {
"type": "customField",
"regex": "^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$",
"customField": "plugin::color-picker.color"
},
"embedTitle": {
"type": "string"
},
"embedBody": {
"type": "richtext"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

/**
* new-user-survey controller
*/

const { createCoreController } = require('@strapi/strapi').factories;

module.exports = createCoreController('api::new-user-survey.new-user-survey');
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

/**
* new-user-survey router
*/

const { createCoreRouter } = require('@strapi/strapi').factories;

module.exports = createCoreRouter('api::new-user-survey.new-user-survey');
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

/**
* new-user-survey service
*/

const { createCoreService } = require('@strapi/strapi').factories;

module.exports = createCoreService('api::new-user-survey.new-user-survey');
5,162 changes: 2,922 additions & 2,240 deletions packages/backend/yarn.lock

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions packages/bot/src/lib/api/newUserSurvey.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const endpoint = 'new-user-survey';

module.exports = ({ request }) => ({
async getSurvey() {
const response = await request({ endpoint, params });

if (response.data && response.data.length) {
return response.data;
}

return {
data: {
id: 1,
attributes: {
createdAt: '2023-02-01T20:29:43.010Z',
updatedAt: '2023-02-01T20:31:07.579Z',
embedColor: '#5700df',
embedTitle: '🙋‍♀️ Hello',
embedBody:
"You are now a member of the growing community at Strapi Community Discord Server. We have members from all over the world who build awesome projects, and support each other.\n\n👋 We'd **love** to get to know you a bit better, so please **[fill out this short survey](https://strapi.typeform.com/to/TLM3Ae?channel=U01JT604ER2)** then introduce yourself in the [#introduction channel](https://discord.gg/2ZVmbQAuKW)!\n\nIf you're stuck for things to say, here are a few ideas:\n\n- Where you're from? \n- What tech stack do you use? \n- Your experience with Strapi?\n- What have you been working on?",
},
},
meta: {},
};
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class GuildMemberAddSendSurvey extends Listener {
}

async run(member) {
const { client, logger } = this.container;
const { client, logger, $api } = this.container;

const getSurvey = await $api.newUserSurvey.getSurvey();

// dont send survey to bots
if (member.user.bot) {
Expand All @@ -26,7 +28,9 @@ class GuildMemberAddSendSurvey extends Listener {
try {
const joinedUser = await client.users.fetch(member.id);
logger.debug(`Sending new user message to: ${joinedUser.username}`);
await joinedUser.send({ embeds: [this.buildSurveyMessage(joinedUser)] });
await joinedUser.send({
embeds: [this.buildSurveyMessage(joinedUser, getSurvey)],
});
} catch (error) {
logger.error(
`The following error occurred while attempting to send the survey to a new member ${error.message}`
Expand All @@ -40,13 +44,13 @@ class GuildMemberAddSendSurvey extends Listener {
* @param {User} user
* @returns {MessageEmbed} embed The survey embed to send
*/
buildSurveyMessage(user) {
buildSurveyMessage(user, getSurvey) {
console.log(getSurvey);

return new MessageEmbed()
.setColor('#5700df')
.setTitle(`🙋‍♀️ Hello ${user.username}`)
.setDescription(
`You are now a member of the growing community at Strapi Community Discord Server. We have members from all over the world who build awesome projects, and support each other.\n\n👋 We'd **love** to get to know you a bit better, so please **[fill out this short survey](https://strapi.typeform.com/to/TLM3Ae?channel=U01JT604ER2)** then introduce yourself in the [#introduction channel](https://discord.gg/2ZVmbQAuKW)! \n\nIf you're stuck for things to say, here are a few ideas: \n- Where you're from? \n- What tech stack do you use? \n- Your experience with Strapi? \n- What have you been working on?`
)
.setDescription(`This is a TEST hello ${user.username}`)
.setTimestamp();
}
}
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2726,7 +2726,7 @@ kind-of@^6.0.2, kind-of@^6.0.3:
resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-6.0.3.tgz#07c05034a6c349fa06e24fa35aa76db4580ce4dd"
integrity sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==

lerna@4.0.0:
lerna@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/lerna/-/lerna-4.0.0.tgz#b139d685d50ea0ca1be87713a7c2f44a5b678e9e"
integrity sha512-DD/i1znurfOmNJb0OBw66NmNqiM8kF6uIrzrJ0wGE3VNdzeOhz9ziWLYiRaZDGGwgbcjOo6eIfcx9O5Qynz+kg==
Expand Down