Skip to content

Feature: Create API Endpoint for Slack Bot Prompt Submissions #39

@sirkitree

Description

@sirkitree

Goal:

Implement a secure API endpoint to accept prompt submissions originating from the Lullabot Slack bot via the /add-prompt command, as outlined in Lullabot/lullabot-slackbot#71.

Requirements:

  1. Endpoint:
    • Route: Define a suitable route (e.g., /api/submit-prompt).
    • Method: Accept POST requests.
    • Authentication: Require an Authorization: Bearer <SHARED_SECRET> header. The SHARED_SECRET should be configurable via environment variables for secure deployment.
  2. Request Payload (JSON):
    • Expect a JSON body with the following fields:
      • content: (string) The full text content of the original Slack message.
      • author: (string) The display name or username of the original Slack message author.
      • invoker: (string) The display name or username of the Slack user who invoked the /add-prompt command.
      • permalink: (string) The permalink URL to the original Slack message.
  3. Core Logic:
    • Validate the incoming request (Authentication, presence of required fields).
    • Authenticate with the GitHub API using a securely stored token (e.g., a GitHub PAT or GitHub App credential managed within this project's secrets, NOT passed from the Slack bot).
    • Create a new issue in this repository (lullabot/prompt_library).
      • Title: New Prompt Submission from Slack: @[Original Slack Author Name] (using the author field from the payload).
      • Body:
        [Full text content from payload's `content` field]
        
        ---
        *Metadata:*
        *   Submitted via `/add-prompt` by: @[Invoking Slack User Name] (from `invoker` field)
        *   Original Author: @[Original Slack Author Name] (from `author` field)
        *   Original Slack Message: [Link from `permalink` field]
        
      • Labels: Apply default labels like new-prompt, from-slack (configurable via environment variables if desired).
  4. Response Payload (JSON):
    • On successful issue creation: Return status 201 Created with JSON body:
      {
        "success": true,
        "issueUrl": "https://github.com/Lullabot/prompt_library/issues/[new_issue_number]"
      }
    • On failure (authentication error, validation error, GitHub API error): Return appropriate error status (e.g., 400, 401, 500) with JSON body:
      {
        "success": false,
        "error": "Descriptive error message"
      }

Depends On: Lullabot/lullabot-slackbot#71

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions