Skip to main content

Command line interface for handling LINE Rich menus via Messaging API

Project description

NIEL

Niel Banner

$ pip install niel
> ...
$ niel
> Usage: niel [OPTIONS] COMMAND [ARGS]...
>
>   niel
>
> Options:
>   --version  Show the version and exit.
>   --help     Show this message and exit.
>
> Commands:
>   auth         Start an authenticated session
>   create       Create a new rich menu
>   default      Show default rich menu identifier
>   drop         Drop rich menu identified by `menu-id`
>   image        Upload an image found by given `image-path` for the...
>   set-default  Set default rich menu identified by `menu-id`

Authenticate session (janky)

$ niel auth `<line-channel-access-token>`
> # Rewrites `.zshrc` or `.bashrc` with NIEL_AUTH_SESSION appended
$ source ~/.zshrc
> # OR
$ source ~/.bashrc

The next shell environment you open, will now have $NIEL_AUTH_SESSION defined as your inserted line-channel-access-token.

Next step, create a RichMenu with defined YAML-file

$ niel create example.yml
> richmenu-fd5610793084b22a00a8eeb3812d5dd8

The YAML-file needs to follow requirements defined by RichMenu object definitions set by LINE Messaging API documentation for RichMenu object [4] found in the appendix. The basics of a RichMenu object definition is as such:

RichMenu Schema
RichMenu {
  areas: [{
    action: {
      altUri.desktop?: string  // optional; utilized when action is "uri".
      clipboardText?: string  // required when action is "clipboard". (character limit: 1,000)
      data?: string // required when action is "datetimepicker", "postback", or "richmenuswitch". (character limit: 300)
      displayText?: string  // optional; utilized when action is "postback".
      initial?: string // optional; utilized when action is "datetimepicker".
      inputOption?: string  // optional; utilized when action is "postback".
      label?: string  // required when action is "camera", "cameraRoll", or "location".
      max?: string  // optional; utilized when action is "datetimepicker".
      min?: string  // optional; utilized when action is "datetimepicker".
      mode?: "date" | "datetime" | "time"  // required when action is "datetimepicker".
      richMenuAliasId?: string  // required when action is "richmenuswitch". Must be valid RichMenu identifier.
      text?: string  // required when action is "message". (character limit: 300)
      type: "camera"
        | "cameraRoll"
        | "clipboard"
        | "datetimepicker"
        | "location"
        | "message"
        | "postback"
        | "richmenuswitch"
        | "uri"
      uri?: string  // required when action is "uri".
    }
    bounds: {
      height: number
      width: number
      x: number
      y: number
    }
  }]
  size: {
    height: number
    width: number
  }
}

See more details on Action objects [1], Area objects [2], Bounds objects [3] and RichMenu objects [4] schemas and criteria under the appendix section.

Upload an image for your preferred RichMenu

$ niel image default.png richmenu-fd5610793084b22a00a8eeb3812d5dd8
> True

Set desired RichMenu with image uploaded as the default RichMenu

$ niel set-default richmenu-fd5610793084b22a00a8eeb3812d5dd8
> True

Drop undesired RichMenu

$ niel drop richmenu-fd5610793084b22a00a8eeb3812d5dd8
> True

Unable to repeatedly drop the same RichMenu identified by menu-id

$ niel drop richmenu-fd5610793084b22a00a8eeb3812d5dd8
> False

Disclosures

Feel free to make an issue if any vulnerabilities are found in the project. Also, this command-line interface relies on the following dependencies so if any of them have been found to be vulnerable, please create an issue and clarify as such.

  • click - Python composable command line interface toolkit
  • httpx - A next generation HTTP client for Python. 🦋
  • pydantic - Data validation using Python type hints
  • rich - Rich text and beautiful formatting in the terminal
  • yaml - Canonical source repository for PyYAML

Contributions

Unless LINE Messaging API changes, no planned changes on the project. But if you want to try your hand at the project, here is the recommended set-up for your local development environmnet.

$ pip install poetry
> ...
$ poetry shell
> ...
$ poetry install --with dev  # Install with development dependencies
> ...

This project has two development dependencies as such:

  • mypy - Optional static typing for Python
  • ruff - An extremely fast Python linter and code formatter, written in Rust.

Recommended usage of said development dependencies.

$ mypy .
> ... # A mypy cache folder will be created on root directory under the name `.mypy_cache`
$ ruff format .
> ... # Python files will be formatted according to the rules defined in `pyproject.toml` with cache under `.ruff`

Roadmap

  • Add command to list richmenus as found on this documentation section.
  • Add command to check if given YAML-file is a valid richmenu as found on this documentation section.
  • Add command to download previously uploaded RichMenu image. as found on this documentaion section.

Appendix

  1. LINE Developers - Area objects
  2. LINE Developers - Action objects
  3. LINE Developers - Bounds objects
  4. LINE Developers - Rich menu objects

License

This project is licensed under the terms of the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

niel-0.1.1.tar.gz (75.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

niel-0.1.1-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file niel-0.1.1.tar.gz.

File metadata

  • Download URL: niel-0.1.1.tar.gz
  • Upload date:
  • Size: 75.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.18

File hashes

Hashes for niel-0.1.1.tar.gz
Algorithm Hash digest
SHA256 beb81eb6b0bf563e3a969e88d6e6185d0f33d46c60b62372699648a14c1bb1bf
MD5 cb072c95fe076613167d43b797b8bebb
BLAKE2b-256 c8d62b319db3c345221ced5c60352a6f8a601b14c9f32e030bc2f6b13ea6885e

See more details on using hashes here.

File details

Details for the file niel-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: niel-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.18

File hashes

Hashes for niel-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba75d7ea84b280a870035d0b2357ea8c602cb99daa931fcffd2c8d97387463cb
MD5 3fd9003c16e08f5a6073946f17d39a8d
BLAKE2b-256 de41c1bdbe7b4c50809654e63483b42ea70ac297f0d15a23f2b3d0a738be35f5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page