Skip to content

Commit

Permalink
Merge pull request #58 from Gurubase/task/discord-slack-bots
Browse files Browse the repository at this point in the history
Task/discord slack bots
  • Loading branch information
fatihbaltaci authored Jan 26, 2025
2 parents 05f9256 + ddcbbe4 commit 928a9d9
Show file tree
Hide file tree
Showing 46 changed files with 3,343 additions and 358 deletions.
204 changes: 3 additions & 201 deletions src/gurubase-backend/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,223 +101,25 @@
"problemMatcher": []
},
{
"label": "Populate alaz requests",
"label": "discord_listener",
"type": "shell",
"command": "python manage.py populate_alaz_requests ${input:edges} ${input:req_per_edge} ${input:monitoring_id}",
"command": "python manage.py discordListener",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Populate alaz resources",
"type": "shell",
"command": "python manage.py populate_mock_resources ${input:count} ${input:monitoring_id}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Clear alaz requests",
"type": "shell",
"command": "python manage.py clear_alaz_requests ${input:monitoring_id}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Create dummy containers",
"type": "shell",
"command": "python manage.py create_dummy_containers ${input:name} ${input:pod} ${input:cluster_uid} ${input:count}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Get asked resources",
"type": "shell",
"command": "python manage.py get_asked_resources ${input:type} ${input:cluster_uid} ${input:update_count} ${input:create_count}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Generate request payload in line protocol for influxdb",
"type": "shell",
"command": "python manage.py generate_alaz_request_payload_for_influxdb ${input:start_timestamp_ms} ${input:end_timestamp_ms} ${input:monitoring_id} ${input:file_name}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Generate dist_tracing resources",
"type": "shell",
"command": "python manage.py populate_dist_tracing ${input:traffic_count} ${input:span_count} ${input:trace_count} ${input:monitoring_id}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Generate random users",
"type": "shell",
"command": "python manage.py generate_random_users ${input:count}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Generate random clusters",
"type": "shell",
"command": "python manage.py generate_random_clusters ${input:count}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Generate cluster created events",
"type": "shell",
"command": "python manage.py generate_cluster_created ${input:count}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Generate test created events",
"type": "shell",
"command": "python manage.py generate_test_created ${input:count}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
},
{
"label": "Generate user logged in events",
"type": "shell",
"command": "python manage.py generate_user_logged_in ${input:count}",
"options": {
"cwd": "${workspaceFolder}/backend"
},
"problemMatcher": [
"$eslint-compact"
]
"problemMatcher": []
}
],
"inputs": [
{
"id": "count",
"type": "promptString",
"description": "Number of resources",
"default": "50"
},
{
"id": "update_count",
"type": "promptString",
"description": "Number of resources to update",
"default": "50"
},
{
"id": "create_count",
"type": "promptString",
"description": "Number of resources to create",
"default": "50"
},
{
"id": "edges",
"type": "promptString",
"description": "Number of edges to populate",
"default": "50"
},
{
"id": "req_per_edge",
"type": "promptString",
"description": "Number of requests per edge",
"default": "20"
},
{
"id": "monitoring_id",
"type": "promptString",
"description": "Monitoring id"
},
{
"id": "cluster_uid",
"type": "promptString",
"description": "Cluster uid"
},
{
"id": "name",
"type": "promptString",
"description": "Name of the resource",
},
{
"id": "pod",
"type": "promptString",
"description": "Pod uid",
},
{
"id": "type",
"type": "promptString",
"description": "Type of the resource",
},
{
"id": "start_timestamp_ms",
"type": "promptString",
"description": "Start timestamp in milliseconds",
},
{
"id": "end_timestamp_ms",
"type": "promptString",
"description": "End timestamp in milliseconds",
},
{
"id": "file_name",
"type": "promptString",
"description": "File name",
},
{
"id": "traffic_count",
"type": "promptString",
"description": "Traffic count",
},
{
"id": "span_count",
"type": "promptString",
"description": "Span count",
},
{
"id": "trace_count",
"type": "promptString",
"description": "Trace count",
}
]
}
120 changes: 120 additions & 0 deletions src/gurubase-backend/INTEGRATION_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
1. First and foremost, set this in backend env
- `PROD_BACKEND_URL`
2. After you receive your OAuth button url, make sure you update it inside `IntegrationContent` component. It is currently hardcoded for local testing env.

```
const integrationConfig = {
slack: {
name: "Slack",
description:
"By connecting your account, you can easily share all your posts and invite your friends.",
iconSize: "w-5 h-5",
url: `https://slack.com/oauth/v2/authorize?client_id=8327841447732.8318709976774&scope=channels:history,channels:join,channels:read,chat:write,groups:history,im:history,groups:read,mpim:read,im:read&user_scope=channels:history,chat:write,channels:read,groups:read,groups:history,im:history`,
icon: SlackIcon
},
discord: {
name: "Discord",
description:
"Connect your Discord account to share content and interact with your community.",
bgColor: "bg-[#5865F2]",
iconSize: "w-5 h-5",
url: `https://discord.com/oauth2/authorize?client_id=1331218460075757649&permissions=8&response_type=code&redirect_uri=https%3A%2F%2Fe306-34-32-48-186.ngrok-free.app%2FOAuth&integration_type=0&scope=identify+bot`,
icon: DiscordIcon
}
};
```



# Discord

1. Go to https://discord.com/developers/applications
2. Click "New Application" and follow up
3. Go to Bot and set these as backend envs:
- `DISCORD_BOT_TOKEN`
4. Go to OAuth2 and set these as backend envs:
- `DISCORD_CLIENT_ID`
- `DISCORD_CLIENT_SECRET`
5. Add the following to Redirects:
- `${frontend_url}/OAuth`
6. Then, pick the appropriate scopes and permissions
- Identify
- Bot
7. Select your redirect url
- `${frontend_url}/OAuth`
8. Pick appropriate bot permissions
- The minimum set is currently untested. You can pick Administrator for now.
9. Pick Guild Install as Integration Type
10. Copy the generated url as the Discord integration button url


## Envs

- `DISCORD_CLIENT_ID`: Found in OAuth2
- `DISCORD_CLIENT_SECRET`: Found in OAuth2
- `DISCORD_REDIRECT_URI`: `${frontend_url}/OAuth`
- `DISCORD_BOT_TOKEN`: Found in Bot

## Usage
1. Run `discordListener`
- `python manage.py discordListener`
2. Set it up from frontend
3. Add the channels
4. Mention the bot and ask a question in that channel

# Slack

1. Go to https://api.slack.com/apps
2. Click Create New App
3. Click from scratch
4. Pick a workspace for now
5. Go to Basic Information and set these as backend envs:
- `SLACK_CLIENT_ID`
- `SLACK_CLIENT_SECRET`
6. Go to OAuth & Permissions and add this as Redirect URL:
- `${frontend_url}/OAuth`
7. Go to Event Subscriptions and add this as Request URL:
- `${backend_url}/slack/events`
8. Go to Intergrations and add this as Redirect URL:
- `${frontend_url}/OAuth`
9. Add these as Bot and User Token scopes:
- Bot
- `channels:history`
- `channels.join`
- `channels:read`
- `chat:write`
- `groups:history`
- `groups:read`
- `im:history`
- `im:read`
- `npim:read`
- User
- `channels:history`
- `channels:read`
- `chat:write`
- `groups:history`
- `groups:read`
- `im:history`
10. Then, go to Event Subscriptions
11. Enable it
12. Set this as request url:
- `${backend_url}/slack/events`
13. Add these as Subscribe to bot events:
- message.channels
14. Go to Manage Distribution
15. Click and confirm "Remove Hard Coded Information"
16. Activate Public Distribution
17. Then, copy the Sharable URL to use it as button url.


## Envs

- `SLACK_CLIENT_ID`: Found in Basic Information
- `SLACK_CLIENT_SECRET`: Found in Basic Information


## Usage
1. Run the backend
2. Set it up from frontend
3. Add the channels
4. Mention the bot and ask a question in that channel
10 changes: 10 additions & 0 deletions src/gurubase-backend/backend/backend/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,4 +404,14 @@
if ENV == "selfhosted":
NGINX_BASE_URL = config('NGINX_BASE_URL', default='http://gurubase-nginx:8029')

DISCORD_CLIENT_ID = config('DISCORD_CLIENT_ID', default='')
DISCORD_CLIENT_SECRET = config('DISCORD_CLIENT_SECRET', default='')
DISCORD_REDIRECT_URI = config('DISCORD_REDIRECT_URI', default='')
DISCORD_BOT_TOKEN = config('DISCORD_BOT_TOKEN', default='')

SLACK_CLIENT_ID = config('SLACK_CLIENT_ID', default='')
SLACK_CLIENT_SECRET = config('SLACK_CLIENT_SECRET', default='')
PROD_BACKEND_URL = config('PROD_BACKEND_URL', default='https://kubernetesguru-backend-api.getanteon.com')


API_CONCURRENCY_THROTTLE_RATE = config('API_CONCURRENCY_THROTTLE_RATE', default='10/m')
7 changes: 7 additions & 0 deletions src/gurubase-backend/backend/backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@
path('api/v1/<str:guru_type>/data-sources/', core_views.api_data_sources, name='api-data-sources'),
path('api/v1/<str:guru_type>/data-sources/reindex/', core_views.api_reindex_data_sources, name='api-reindex-data-sources'),
# path('api/v1/<str:guru_type>/data-sources/privacy/', core_views.api_update_data_source_privacy, name='api-update-data-source-privacy'),

path('slack/events/', core_views.slack_events, name='slack_events'),
path('<str:guru_type>/integrations/', core_views.list_integrations, name='list_integrations'),
path('<str:guru_type>/integrations/<str:integration_type>/', core_views.manage_integration, name='get_integration'),
path('integrations/test_message/', core_views.send_test_message, name='send_test_message'),
path('integrations/create/', core_views.create_integration, name='create_integration'),
path('<str:guru_type>/integrations/<str:integration_type>/channels/', core_views.list_channels, name='list_channels'),
]

if settings.STREAM_ENABLED:
Expand Down
Loading

0 comments on commit 928a9d9

Please sign in to comment.