-
Notifications
You must be signed in to change notification settings - Fork 26
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
Add support for custom metadata events #86
Conversation
Codecov Report
@@ Coverage Diff @@
## main #86 +/- ##
==========================================
+ Coverage 96.21% 96.34% +0.13%
==========================================
Files 43 44 +1
Lines 1610 1669 +59
Branches 87 90 +3
==========================================
+ Hits 1549 1608 +59
Misses 59 59
Partials 2 2
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
3218af2
to
651e17e
Compare
I was unable to test step 1. Here's my ➜ cat manifest.ts
import { Manifest, DefineEvent, Schema } from "deno-slack-sdk/mod.ts";
import { ApprovalWorkflow } from "./workflows/approval.ts";
export const MyEvent = DefineEvent({
name: "my_event",
type: Schema.types.object,
properties: {
id: { type: Schema.types.string },
summary: { type: Schema.types.string },
},
required: ["id", "summary"],
});
export default Manifest({
name: "interactive-approval",
description: "Approving allthethings",
icon: "assets/icon.png",
workflows: [ApprovalWorkflow],
outgoingDomains: [],
botScopes: ["commands", "chat:write", "chat:write.public"],
events: [MyEvent],
}); And here's the output of the
|
Looks like there are issues with the |
Testing notes, continued: Step 2. Using custom type in this way worked fine: const fancyAssBoolean = DefineType({
name: "fancyAssBoolean",
type: Schema.types.object,
properties: {
aBoolean: { type: "boolean" },
},
});
export const MyEvent = DefineEvent({
name: "my_event",
type: fancyAssBoolean,
// required: ["aBoolean"],
}); If I uncomment the
Step 3. Use the event in a postMessage metadata. Worked great! Step 4. Use the event in a postMessage metadata, but where structure doesn't match. So with this Event w/ Custom Type definition: const fancyAssBoolean = DefineType({
name: "fancyAssBoolean",
type: Schema.types.object,
properties: {
aBoolean: { type: "boolean" },
},
});
export const MyEvent = DefineEvent({
name: "my_event",
type: fancyAssBoolean,
// required: ["aBoolean"],
}); I posted a message like so: const resp = await client.chat.postMessage({
channel: inputs.approval_channel_id,
blocks: renderApprovalMessage(inputs),
metadata: {
event_type: MyEvent,
event_payload: {
aBoolean: "string"
},
}
}); ... and no If I posted a message like so: const resp = await client.chat.postMessage({
channel: inputs.approval_channel_id,
blocks: renderApprovalMessage(inputs),
metadata: {
event_type: MyEvent,
event_payload: {
nope: true
},
}
}); Then the above metadata is attached to the message - even though the structure is wrong 🤔 |
Good find @filmaj, but I consider this unrelated to this PR. It's happening because we don't support overriding properties on the CustomType and is falling back to a generic error. We should share this finding with the primitives team and they can decide what to do about it (improve the error or allow this functionality).
This is expected since
This is also expected. The |
constructor( | ||
public definition: Def, | ||
) { | ||
this.id = definition.name; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we just call this name?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose id
because it matches Custom Types and events is pretty much the same. That being said, if we went with name
it will match Datastores (and the property that's being set). I don't have a strong preference here, open to changing if anyone else does!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consistency is good, so am fine w/ this, just couldn't recall if we had odd naming in Types due to callback_id => id => name refactoring, so thought if so, maybe could keep this clearer here.
toJSON() { | ||
return this.generateReferenceString(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it intended for toString() and toJSON() to do the same thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Overwriting these prototype methods is a pattern we follow elsewhere (like in types and workflows) to make sure that when a developer references the CustomEvent
instance, we convert it to what our API endpoints expect for the manifest and API clients rather than the full object.
toJSON()
supports the case where we convert an object into a string to pass to our APIs
toString()
supports the case where devs may want to do something like This is the event: ${MyEvent}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The testing steps, including creating a custom event w/ custom type, and registering an event trigger on that thing, worked. Well done sir.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, and works as described.
Summary
This PR adds support for defining events on the App Manifest.
Feature Details
When an app uses
chat.postMessage
from inside a function, they can optionally pass ametadata
object. Thatmetadata
object will have anevent_type
and anevent_payload
. If theevent_type
matches one of the keys from the app manifest'sevents
object, theevent_payload
needs to match the metadata schema.warning
and aresponse_metadata
object.postMessage
call entirely, but that's not currently supported.additionalProperties: false
SDK Usage
Testing
chat.postMessage
call where your structure matches the expectationchat.postMessage
call where the structure no longer matchesRequirements (place an
x
in each[ ]
)