Skip to content

Instantly share code, notes, and snippets.

@wongjas
Last active December 13, 2022 08:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wongjas/43804c8e9f2213e90be10a04abf1b709 to your computer and use it in GitHub Desktop.
Save wongjas/43804c8e9f2213e90be10a04abf1b709 to your computer and use it in GitHub Desktop.
A list of Slack CLI datastore example commands
// This file shows all the commands within this video: TBD.
// Each datastore operation can be executed within code and also on the command line through the Slack CLI.
// Within this gist, you'll find each CLI command followed by its equivalent in TypeScript.
// Feel free to copy-paste and try them out for yourself.
// Datastore definition
import { DefineDatastore, Schema } from "deno-slack-sdk/mod.ts";
export const MessageDatastore = DefineDatastore({
name: "messages",
primary_key: "id",
attributes: {
id: {
type: Schema.types.string,
},
message: {
type: Schema.types.string,
},
message_type: {
type: Schema.types.string,
},
},
});
export default MessageDatastore;
// manifest.ts
import { Manifest } from "deno-slack-sdk/mod.ts";
import { MessageDatastore } from "./datastores/messages.ts";
export default Manifest({
name: "Datastore testing",
description: "A quick datastore example",
icon: "assets/icon.png",
workflows: [],
outgoingDomains: [],
datastores: [MessageDatastore],
botScopes: [
"chat:write",
"chat:write.public",
"datastore:read",
"datastore:write",
"channels:read",
"triggers:write",
],
});
// PUT
// slack datastore put '{"datastore": "messages", "item": {"id": "2", "message": "I hope all is well", "message_type": "greeting"}}'
const putResponse = await client.apps.datastore.put({
datastore: "messages",
item: {
id: "1",
message: "Hello there, friend.",
message_type: "greeting",
},
});
// GET
// slack datastore get '{"datastore": "messages", "id": "2"}'
const getResponse = await client.apps.datastore.get({
datastore: "messages",
id: "2",
});
// QUERY
// slack datastore query '{"datastore": "messages", "expression": "#message_type = :type", "expression_attributes": {"#message_type": "message_type"}, "expression_values": {":type": "greeting"}}'
const queryResponse = await client.apps.datastore.query({
datastore: "messages",
expression: "#message_type = :type",
expression_attributes: { "#message_type": "message_type" },
expression_values: { ":type": "greeting" },
});
// DELETE
// slack datastore delete '{"datastore": "messages", "id": "2"}'
const deleteResponse = await client.apps.datastore.delete({
datastore: "messages",
id: "2"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment