discord-interactions


Namediscord-interactions JSON
Version 0.4.0 PyPI version JSON
download
home_pagehttps://github.com/discord/discord-interactions-python
SummaryUseful tools for using the Discord Interactions API
upload_time2022-05-17 16:23:51
maintainerIan Webster
docs_urlNone
authorIan Webster
requires_python>=3.6.0,<4.0.0
licenseMIT
keywords discord
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            discord-interactions-python
---
![PyPI - License](https://img.shields.io/pypi/l/discord-interactions)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/discord-interactions)

Types and helper functions for Discord Interactions webhooks.

# Installation

Available via [pypi](https://pypi.org/project/discord-interactions/):

```
pip install discord-interactions
```

# Usage

Use the `InteractionType` and `InteractionResponseType` enums to process and respond to webhooks.

Use `verify_key` to check a request signature:

```py
if verify_key(request.data, signature, timestamp, 'my_client_public_key'):
    print('Signature is valid')
else:
    print('Signature is invalid')
```

Use `verify_key_decorator` to protect routes in a Flask app:

```py
import os

from flask import Flask, request, jsonify

from discord_interactions import verify_key_decorator, InteractionType, InteractionResponseType

CLIENT_PUBLIC_KEY = os.getenv('CLIENT_PUBLIC_KEY')

app = Flask(__name__)

@app.route('/interactions', methods=['POST'])
@verify_key_decorator(CLIENT_PUBLIC_KEY)
def interactions():
  if request.json['type'] == InteractionType.APPLICATION_COMMAND:
    return jsonify({
        'type': InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
        'data': {
            'content': 'Hello world'
        }
    })
```

# Exports

This module exports the following:

### InteractionType

An enum of interaction types that can be POSTed to your webhook endpoint.

### InteractionResponseType

An enum of response types you may provide in reply to Discord's webhook.

### InteractionResponseFlags

An enum of flags you can set on your response data.

### verify_key(raw_body: str, signature: str, timestamp: str, client_public_key: str) -> bool:

Verify a signed payload POSTed to your webhook endpoint.

### verify_key_decorator(client_public_key: str)

Flask decorator that will verify request signatures and handle PING/PONG requests.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/discord/discord-interactions-python",
    "name": "discord-interactions",
    "maintainer": "Ian Webster",
    "docs_url": null,
    "requires_python": ">=3.6.0,<4.0.0",
    "maintainer_email": "ianw_pypi@ianww.com",
    "keywords": "discord",
    "author": "Ian Webster",
    "author_email": "ianw_pypi@ianww.com",
    "download_url": "https://files.pythonhosted.org/packages/9f/61/0fb857ffcbc9a0a946caf0a50874f80ba98798ca583ba59f7f34e22912c0/discord-interactions-0.4.0.tar.gz",
    "platform": null,
    "description": "discord-interactions-python\n---\n![PyPI - License](https://img.shields.io/pypi/l/discord-interactions)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/discord-interactions)\n\nTypes and helper functions for Discord Interactions webhooks.\n\n# Installation\n\nAvailable via [pypi](https://pypi.org/project/discord-interactions/):\n\n```\npip install discord-interactions\n```\n\n# Usage\n\nUse the `InteractionType` and `InteractionResponseType` enums to process and respond to webhooks.\n\nUse `verify_key` to check a request signature:\n\n```py\nif verify_key(request.data, signature, timestamp, 'my_client_public_key'):\n    print('Signature is valid')\nelse:\n    print('Signature is invalid')\n```\n\nUse `verify_key_decorator` to protect routes in a Flask app:\n\n```py\nimport os\n\nfrom flask import Flask, request, jsonify\n\nfrom discord_interactions import verify_key_decorator, InteractionType, InteractionResponseType\n\nCLIENT_PUBLIC_KEY = os.getenv('CLIENT_PUBLIC_KEY')\n\napp = Flask(__name__)\n\n@app.route('/interactions', methods=['POST'])\n@verify_key_decorator(CLIENT_PUBLIC_KEY)\ndef interactions():\n  if request.json['type'] == InteractionType.APPLICATION_COMMAND:\n    return jsonify({\n        'type': InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,\n        'data': {\n            'content': 'Hello world'\n        }\n    })\n```\n\n# Exports\n\nThis module exports the following:\n\n### InteractionType\n\nAn enum of interaction types that can be POSTed to your webhook endpoint.\n\n### InteractionResponseType\n\nAn enum of response types you may provide in reply to Discord's webhook.\n\n### InteractionResponseFlags\n\nAn enum of flags you can set on your response data.\n\n### verify_key(raw_body: str, signature: str, timestamp: str, client_public_key: str) -> bool:\n\nVerify a signed payload POSTed to your webhook endpoint.\n\n### verify_key_decorator(client_public_key: str)\n\nFlask decorator that will verify request signatures and handle PING/PONG requests.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Useful tools for using the Discord Interactions API",
    "version": "0.4.0",
    "project_urls": {
        "Homepage": "https://github.com/discord/discord-interactions-python",
        "Repository": "https://github.com/discord/discord-interactions-python"
    },
    "split_keywords": [
        "discord"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "deef21bb4be7e589c038bd0d73b6be53e045daaf785b4cbb6c6db3dabab810ad",
                "md5": "881e7f982b85e14ba9eb685facbd5f70",
                "sha256": "bc8dcac17873a5bf0b065967b109fabf626a02fe21226369a13e1ee2a6bcd833"
            },
            "downloads": -1,
            "filename": "discord_interactions-0.4.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "881e7f982b85e14ba9eb685facbd5f70",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.0,<4.0.0",
            "size": 3721,
            "upload_time": "2022-05-17T16:23:53",
            "upload_time_iso_8601": "2022-05-17T16:23:53.616757Z",
            "url": "https://files.pythonhosted.org/packages/de/ef/21bb4be7e589c038bd0d73b6be53e045daaf785b4cbb6c6db3dabab810ad/discord_interactions-0.4.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f610fb857ffcbc9a0a946caf0a50874f80ba98798ca583ba59f7f34e22912c0",
                "md5": "7798a0ada3455a7d1f5b4148691f9fa8",
                "sha256": "41bd0289a6460437c7382ec56d99ee604e8cb15259f2d831ae1d248709f8bcb2"
            },
            "downloads": -1,
            "filename": "discord-interactions-0.4.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7798a0ada3455a7d1f5b4148691f9fa8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.0,<4.0.0",
            "size": 3491,
            "upload_time": "2022-05-17T16:23:51",
            "upload_time_iso_8601": "2022-05-17T16:23:51.826640Z",
            "url": "https://files.pythonhosted.org/packages/9f/61/0fb857ffcbc9a0a946caf0a50874f80ba98798ca583ba59f7f34e22912c0/discord-interactions-0.4.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-05-17 16:23:51",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "discord",
    "github_project": "discord-interactions-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "discord-interactions"
}
        
Elapsed time: 0.13303s