JavaScript 的布尔特: Prisma 安装 Store
本单元提供 InstallationStore 执行情况 普里斯马 用户.
开始
您可以使用以下程序创建简单的节点应用项目 package.json 财务报告和审定财务报表 tsconfig.json当然,如果你想使用一些构建工具,例如 网络软件包,你可以自己走,并增加必要的依赖.
软件包.json
{
"name": "bolt-prisma-app",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "rm -rf dist/ && tsc && npx ts-node src/index.ts"
},
"author": "Kazuhiro Sera",
"license": "MIT",
"dependencies": {
"@slack/bolt": "^3.12.2",
"@seratch_/bolt-prisma": "^1.0.0",
"sqlite3": "4.2.0",
"@prisma/client": "^3.9.2"
},
"devDependencies": {
"prisma": "^3.9.2",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
}
}
tsconfig.json (英语)
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowJs": true,
"esModuleInterop": true,
"outDir": "dist",
},
"include": ["src/**/*"]
}
在 api. slack.com/ apps 创建一个新的 Slack 应用程序
下一步是创建一个新的Slack应用配置. 您可以为它使用以下 App Munification 配置数据 .
display_information:
name: prisma-oauth-test-app
features:
bot_user:
display_name: prisma-oauth-test-app
oauth_config:
redirect_urls:
- https://xxx.ngrok.io/slack/oauth_redirect
scopes:
bot:
- commands
- chat:write
- app_mentions:read
settings:
event_subscriptions:
bot_events:
- app_mention
interactivity:
is_enabled: true
socket_mode_enabled: true
配置您的 Prisma 方案
下一步是配置您的 Prisma 计划 .
棱镜/棱镜
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "sqlite"
url = env("DATABASE_URL")
}
model SlackAppInstallation {
@@map("slack_app_installation")
id Int @id @default(autoincrement())
clientId String? @map("client_id")
appId String? @map("app_id")
enterpriseId String? @map("enterprise_id")
enterpriseName String? @map("enterprise_name")
enterpriseUrl String? @map("enterprise_url")
teamId String? @map("team_id")
teamName String? @map("team_name")
botToken String? @map("bot_token")
botId String? @map("bot_id")
botUserId String? @map("bot_user_id")
botScopes String? @map("bot_scopes")
botRefreshToken String? @map("bot_refresh_token")
botTokenExpiresAt DateTime? @map("bot_token_expires_at")
userId String? @map("user_id")
userToken String? @map("user_token")
userScopes String? @map("user_scopes")
userRefreshToken String? @map("user_refresh_token")
userTokenExpiresAt DateTime? @map("user_token_expires_at")
incomingWebhookUrl String? @map("incoming_webhook_url")
incomingWebhookChannel String? @map("incoming_webhook_channel")
incomingWebhookChannelId String? @map("incoming_webhook_channel_id")
incomingWebhookConfigurationUrl String? @map("incoming_webhook_configuration_url")
isEnterpriseInstall Boolean @default(false) @map("is_enterprise_install")
tokenType String @default("bot") @map("token_type")
installedAt DateTime @default(now()) @map("installed_at")
// This is an example custom property
memo String?
}
您可以通过运行以下的昏迷设置基于文件的数据库:
npm i
export DATABASE_URL="file:./dev.db"
npx prisma migrate dev --name init
npx prisma generate
在工程中设置您的源代码
最后一步是在项目中添加你的代码,并转出你的应用程序. 您可以使用以下代码 .
标准/指数.ts
import { App } from '@slack/bolt';
import { ConsoleLogger, LogLevel } from '@slack/logger';
import { PrismaClient } from '@prisma/client';
import { PrismaInstallationStore } from '@seratch_/bolt-prisma';
const logger = new ConsoleLogger();
logger.setLevel(LogLevel.DEBUG);
const prismaClient = new PrismaClient({log: [{emit: 'stdout', level: 'query'}]});
const installationStore = new PrismaInstallationStore({
// The name `slackAppInstallation` can be different
// if you use a different name in your Prisma schema
prismaTable: prismaClient.slackAppInstallation,
clientId: process.env.SLACK_CLIENT_ID,
logger,
});
const app = new App({
socketMode: true,
appToken: process.env.SLACK_APP_TOKEN,
signingSecret: process.env.SLACK_SIGNING_SECRET,
clientId: process.env.SLACK_CLIENT_ID,
clientSecret: process.env.SLACK_CLIENT_SECRET,
stateSecret: process.env.SLACK_STATE_SECRET,
scopes: ['commands', 'chat:write', 'app_mentions:read'],
installerOptions: {
directInstall: true,
},
installationStore,
logger,
});
app.event('app_mention', async ({ event, say }) => {
await say({
text: `<@${event.user}> Hi there :wave:`,
blocks: [
{
type: 'section',
text: {
type: 'mrkdwn',
text: `<@${event.user}> Hi there :wave:`,
},
},
],
});
});
(async () => {
await app.start();
logger.info('⚡️ Bolt app is running!');
})();
最后,你的应用程序现在可以运行了! 设定所有所需的嵌入变量, 击出 npm start,然后启用您的公共 URL 端点( 您可能想要使用一些代理工具, 如 无) (中文(简体) ).
export SLACK_CLIENT_ID=
export SLACK_CLIENT_SECRET=
export SLACK_SIGNING_SECRET=
export SLACK_STATE_SECRET=secret
export SLACK_APP_TOKEN=
npm start
# Visit https://{your public domain}/slack/install
现在您可以将应用程序安装到您的 Lack 工作空间 https://{your public domain}/slack/install玩得开心点!