Skip to content

Commit

Permalink
Improve Deno source examples
Browse files Browse the repository at this point in the history
  • Loading branch information
seratch committed Apr 15, 2024
1 parent 5d71139 commit f482b33
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 37 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,4 @@ dist
tmp/
.DS_Store
.slack/
.vscode/
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,21 @@ cloudflared tunnel --url http://localhost:3000
#### Run with Deno

```typescript
import { SlackApp } from "https://deno.land/x/slack_edge@0.10.8/mod.ts";
import { SlackApp, SlackEdgeAppEnv } from "https://deno.land/x/slack_edge@0.10.9/mod.ts";

const app = new SlackApp({
const app = new SlackApp<SlackEdgeAppEnv>({
env: {
SLACK_SIGNING_SECRET: Deno.env.get("SLACK_SIGNING_SECRET"),
SLACK_SIGNING_SECRET: Deno.env.get("SLACK_SIGNING_SECRET")!,
SLACK_BOT_TOKEN: Deno.env.get("SLACK_BOT_TOKEN"),
SLACK_LOGGING_LEVEL: "DEBUG",
},
});

// Add listeners here

import { serve } from "https://deno.land/std@0.221.0/http/server.ts";
await serve(
async (request) => {
return await app.run(request);
},
{ port: 3000 }
await Deno.serve(
{ port: 3000 },
async (request) => { return await app.run(request); },
);
```

Expand All @@ -220,12 +217,12 @@ cloudflared tunnel --url http://localhost:3000
Thanks to Deno's built-in WebSocket implementation, you can quickly and easily run a Socket Mode app as below:

```typescript
import { SlackApp } from "https://deno.land/x/slack_edge@0.10.8/mod.ts";
import { SlackApp, SlackSocketModeAppEnv } from "https://deno.land/x/slack_edge@0.10.9/mod.ts";

const app = new SlackApp({
const app = new SlackApp<SlackSocketModeAppEnv>({
env: {
SLACK_APP_TOKEN: Deno.env.get("SLACK_APP_TOKEN")!,
SLACK_BOT_TOKEN: Deno.env.get("SLACK_BOT_TOKEN"),
SLACK_APP_TOKEN: Deno.env.get("SLACK_APP_TOKEN"),
SLACK_LOGGING_LEVEL: "DEBUG",
},
});
Expand Down
23 changes: 11 additions & 12 deletions test/test-app-deno-oauth.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SlackAPIClient } from "https://deno.land/x/slack_web_api_client@0.8.0/mod.ts";
import { SlackAPIClient } from "https://deno.land/x/slack_web_api_client@0.10.2/mod.ts";
import {
Authorize,
SlackOAuthApp,
Expand Down Expand Up @@ -48,10 +48,10 @@ class FileInstallationStore implements InstallationStore<SlackOAuthEnv> {
return {
enterpriseId: installation?.enterprise_id,
teamId: installation?.team_id,
botId: authTest.bot_id,
botUserId: installation.bot_user_id,
botToken: installation.bot_token,
botScopes: installation.bot_scopes,
botId: authTest.bot_id!,
botUserId: installation.bot_user_id!,
botToken: installation.bot_token!,
botScopes: installation.bot_scopes!,
};
}
throw new AuthorizeError(
Expand All @@ -61,11 +61,11 @@ class FileInstallationStore implements InstallationStore<SlackOAuthEnv> {
}
}

const app = new SlackOAuthApp({
const app = new SlackOAuthApp<SlackOAuthEnv>({
env: {
SLACK_SIGNING_SECRET: Deno.env.get("SLACK_SIGNING_SECRET"),
SLACK_CLIENT_ID: Deno.env.get("SLACK_CLIENT_ID"),
SLACK_CLIENT_SECRET: Deno.env.get("SLACK_CLIENT_SECRET"),
SLACK_SIGNING_SECRET: Deno.env.get("SLACK_SIGNING_SECRET")!,
SLACK_CLIENT_ID: Deno.env.get("SLACK_CLIENT_ID")!,
SLACK_CLIENT_SECRET: Deno.env.get("SLACK_CLIENT_SECRET")!,
SLACK_BOT_SCOPES: "app_mentions:read,chat:write,channels:history,commands",
SLACK_LOGGING_LEVEL: "DEBUG",
},
Expand Down Expand Up @@ -109,10 +109,9 @@ app.shortcut(

// deno run --watch --allow-net --allow-env --allow-read --allow-write test/test-app-deno-oauth.ts
// ngrok http 3000 --subdomain your-domain
import { serve } from "https://deno.land/std@0.216.0/http/server.ts";
await serve(
await Deno.serve(
{ port: 3000 },
async (request) => {
return await app.run(request);
},
{ port: 3000 },
);
11 changes: 5 additions & 6 deletions test/test-app-deno.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { SlackApp } from "../src_deno/app.ts";
import { SlackApp, SlackEdgeAppEnv } from "../src_deno/mod.ts";

const app = new SlackApp({
const app = new SlackApp<SlackEdgeAppEnv>({
env: {
SLACK_SIGNING_SECRET: Deno.env.get("SLACK_SIGNING_SECRET"),
SLACK_SIGNING_SECRET: Deno.env.get("SLACK_SIGNING_SECRET")!,
SLACK_BOT_TOKEN: Deno.env.get("SLACK_BOT_TOKEN"),
SLACK_LOGGING_LEVEL: "DEBUG",
},
Expand Down Expand Up @@ -44,10 +44,9 @@ app.shortcut(

// deno run --watch --allow-net --allow-env test/test-app-deno.ts
// ngrok http 3000 --subdomain your-domain
import { serve } from "https://deno.land/std@0.216.0/http/server.ts";
await serve(
await Deno.serve(
{ port: 3000 },
async (request) => {
return await app.run(request);
},
{ port: 3000 },
);
14 changes: 7 additions & 7 deletions test/test-socket-mode-app-deno.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SlackApp } from "../src_deno/mod.ts";
import { SlackApp, SlackSocketModeAppEnv } from "../src_deno/mod.ts";

const app = new SlackApp({
const app = new SlackApp<SlackSocketModeAppEnv>({
env: {
SLACK_APP_TOKEN: Deno.env.get("SLACK_APP_TOKEN")!,
SLACK_BOT_TOKEN: Deno.env.get("SLACK_BOT_TOKEN"),
SLACK_APP_TOKEN: Deno.env.get("SLACK_APP_TOKEN"),
SLACK_LOGGING_LEVEL: "DEBUG",
},
});
Expand Down Expand Up @@ -81,7 +81,7 @@ app.action(
async ({ context, payload }) => {
const { client } = context;
await client.views.open({
trigger_id: context.triggerId,
trigger_id: context.triggerId!,
view: {
type: "modal",
callback_id: "remote-function-modal",
Expand All @@ -100,8 +100,8 @@ app.action(
},
});
await client.chat.update({
channel: payload.container.channel_id,
ts: payload.container.message_ts,
channel: payload.container.channel_id!,
ts: payload.container.message_ts!,
text: "Thank you!",
});
},
Expand All @@ -116,7 +116,7 @@ app.view(
const user_id = payload.function_data!.inputs.user_id;
const { client } = context;
await client.functions.completeSuccess({
function_execution_id: context.functionExecutionId,
function_execution_id: context.functionExecutionId!,
outputs: { user_id },
});
},
Expand Down

0 comments on commit f482b33

Please sign in to comment.