Skip to content

Commit

Permalink
Better block info, fix tests issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Mar 29, 2024
1 parent 7286dd8 commit 19b4ff7
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 35 deletions.
36 changes: 27 additions & 9 deletions src/lib/slack.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export default class Slack {
}

static createSlackMessagePayload(reportRequest) {
const longText = `Pubkey \`${reportRequest.reporterPubkey}\` reported an event:\n\`\`\`\n${reportRequest.reporterText}\n\`\`\``;

const shortText = `${reportRequest.reporterPubkey} reported event ${reportRequest.reportedEvent.id}`;
const text = `New Nostr Event to moderate requested by pubkey \`${reportRequest.reporterPubkey}\``;

const elements = Object.entries(OPENAI_CATEGORIES).map(
([category, categoryData]) => {
Expand All @@ -40,10 +38,11 @@ export default class Slack {
type: "plain_text",
text: category,
},
value: JSON.stringify([
categoryData.nip56_report_type,
categoryData.nip69,
]),
value: JSON.stringify({
reporterPubkey: reportRequest.reporterPubkey,
nip56_report_type: categoryData.nip56_report_type,
nip69: categoryData.nip69,
}),
action_id: category,
};
}
Expand All @@ -61,15 +60,33 @@ export default class Slack {

return {
channel: channelId,
text: shortText,
text,
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: longText,
text,
},
},
{
type: "rich_text",
block_id: "reporterText",
elements: [
{
type: "rich_text_preformatted",
elements: [
{
type: "text",
text:
reportRequest.reporterText ||
"No text provided by reporter",
},
],
border: 0,
},
],
},
{
type: "rich_text",
block_id: "reportedEvent",
Expand All @@ -79,6 +96,7 @@ export default class Slack {
elements: [
{
type: "text",
style: { code: true },
text: JSON.stringify(reportRequest.reportedEvent, null, 2),
},
],
Expand Down
7 changes: 6 additions & 1 deletion test/moderationFunction.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ describe("Moderation Cloud Function", async () => {
const nostrEventsPubSub = getFunction("nostrEventsPubSub");
await nostrEventsPubSub(cloudEvent);

sinon.assert.calledOnce(Nostr.publishNostrEvent);
sinon.assert.calledWithMatch(Nostr.publishNostrEvent, {
kind: 1984,
tags: [
Expand Down Expand Up @@ -354,6 +353,9 @@ describe("Moderation Cloud Function", async () => {
],
});

sinon
.stub(Nostr, "getReportedNostrEvent")
.returns(Promise.resolve(flaggedNostrEvent));
const nostrEventsPubSub = getFunction("nostrEventsPubSub");
await nostrEventsPubSub(cloudEvent);

Expand Down Expand Up @@ -417,6 +419,9 @@ describe("Moderation Cloud Function", async () => {
],
});

sinon
.stub(Nostr, "getReportedNostrEvent")
.returns(Promise.resolve(flaggedNostrEvent));
const nostrEventsPubSub = getFunction("nostrEventsPubSub");
await nostrEventsPubSub(cloudEvent);

Expand Down
119 changes: 94 additions & 25 deletions test/slack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,31 @@ describe("Slack", () => {

expect(slackMessagePayload).to.be.eql({
channel: "bar",
text: "npub123 reported event 12",
text: "New Nostr Event to moderate requested by pubkey `npub123`",
blocks: [
{
type: "section",
text: {
type: "mrkdwn",
text: "Pubkey npub123 reported an event:\n```\nundefined\n```",
text: "New Nostr Event to moderate requested by pubkey `npub123`",
},
},
{
type: "rich_text",
block_id: "reporterText",
elements: [
{
type: "rich_text_preformatted",
elements: [
{
text: "No text provided by reporter",
type: "text",
},
],
border: 0,
},
],
},
{
type: "rich_text",
block_id: "reportedEvent",
Expand All @@ -65,7 +81,7 @@ describe("Slack", () => {
elements: [
{
type: "text",
style: "code",
style: { code: true },
text: '{\n "id": "12",\n "pubkey": "34",\n "created_at": 1673347337,\n "kind": 1,\n "content": "Foobar",\n "tags": [\n [\n "e",\n "56"\n ],\n [\n "p",\n "78"\n ]\n ],\n "sig": "91"\n}',
},
],
Expand All @@ -78,68 +94,121 @@ describe("Slack", () => {
elements: [
{
type: "button",
text: { type: "plain_text", text: "hate" },
value: '["other","IH"]',
text: {
type: "plain_text",
text: "Skip",
},
value: "skip",
action_id: "skip",
},
{
type: "button",
text: {
type: "plain_text",
text: "hate",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"other","nip69":"IH"}',
action_id: "hate",
},
{
type: "button",
text: { type: "plain_text", text: "hate/threatening" },
value: '["other","HC-bhd"]',
text: {
type: "plain_text",
text: "hate/threatening",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"other","nip69":"HC-bhd"}',
action_id: "hate/threatening",
},
{
type: "button",
text: { type: "plain_text", text: "harassment" },
value: '["other","IL-har"]',
text: {
type: "plain_text",
text: "harassment",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"other","nip69":"IL-har"}',
action_id: "harassment",
},
{
type: "button",
text: { type: "plain_text", text: "harassment/threatening" },
value: '["other","HC-bhd"]',
text: {
type: "plain_text",
text: "harassment/threatening",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"other","nip69":"HC-bhd"}',
action_id: "harassment/threatening",
},
{
type: "button",
text: { type: "plain_text", text: "self-harm" },
value: '["other","HC-bhd"]',
text: {
type: "plain_text",
text: "self-harm",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"other","nip69":"HC-bhd"}',
action_id: "self-harm",
},
{
type: "button",
text: { type: "plain_text", text: "self-harm/intent" },
value: '["other","HC-bhd"]',
text: {
type: "plain_text",
text: "self-harm/intent",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"other","nip69":"HC-bhd"}',
action_id: "self-harm/intent",
},
{
type: "button",
text: { type: "plain_text", text: "self-harm/instructions" },
value: '["other","HC-bhd"]',
text: {
type: "plain_text",
text: "self-harm/instructions",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"other","nip69":"HC-bhd"}',
action_id: "self-harm/instructions",
},
{
type: "button",
text: { type: "plain_text", text: "sexual" },
value: '["nudity","NS"]',
text: {
type: "plain_text",
text: "sexual",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"nudity","nip69":"NS"}',
action_id: "sexual",
},
{
type: "button",
text: { type: "plain_text", text: "sexual/minors" },
value: '["illegal","IL-csa"]',
text: {
type: "plain_text",
text: "sexual/minors",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"illegal","nip69":"IL-csa"}',
action_id: "sexual/minors",
},
{
type: "button",
text: { type: "plain_text", text: "violence" },
value: '["other","VI"]',
text: {
type: "plain_text",
text: "violence",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"other","nip69":"VI"}',
action_id: "violence",
},
{
type: "button",
text: { type: "plain_text", text: "violence/graphic" },
value: '["other","VI"]',
text: {
type: "plain_text",
text: "violence/graphic",
},
value:
'{"reporterPubkey":"npub123","nip56_report_type":"other","nip69":"VI"}',
action_id: "violence/graphic",
},
],
Expand Down

0 comments on commit 19b4ff7

Please sign in to comment.