Skip to main content

LINE Works SDK for Python

Project description

line-works-sdk

LINE WORKS SDK for Python

Talk API is defined in OpenAPI 3.1.0 (here).

This library uses code automatically generated by openapi-generator-cli.

Requirements

Python 3.11+

Installation

$ pip install line-works-sdk

dev version

https://pypi.org/project/line-works-sdk/#history

$ pip install line-works-sdk==x.x.devyyyymmddHHMM

Usage

import json

from line_works.client import LineWorks
from line_works.mqtt.enums.notification_type import NotificationType
from line_works.mqtt.enums.packet_type import PacketType
from line_works.mqtt.models.packet import MQTTPacket
from line_works.mqtt.models.payload.message import MessagePayload
from line_works.openapi.talk.models.flex_content import FlexContent
from line_works.tracer import LineWorksTracer


def receive_publish_packet(w: LineWorks, p: MQTTPacket) -> None:
    payload = p.payload

    if not isinstance(payload, MessagePayload):
        return

    if not payload.channel_no:
        return

    print(f"{payload!r}")

    if payload.loc_args1 == "test":
        w.send_text_message(payload.channel_no, "ok")

    elif payload.loc_args1 == "/msg":
        w.send_text_message(payload.channel_no, f"{payload!r}")

    elif payload.loc_args1 == "/flex":
        with open("src/sample_flex.json") as f:
            j: dict = json.load(f)
        w.send_flex_message(
            payload.channel_no,
            flex_content=FlexContent(alt_text="test", contents=j),
        )

    if payload.notification_type == NotificationType.NOTIFICATION_STICKER:
        w.send_text_message(payload.channel_no, "スタンプ")
        w.send_text_message(payload.channel_no, f"{payload.sticker=}")

        w.send_sticker_message(payload.channel_no, payload.sticker)


WORKS_ID = "YOUR WORKS ID"
PASSWORD = "YOUR WORKS PASSWORD"

works = LineWorks(works_id=WORKS_ID, password=PASSWORD)

my_info = works.get_my_info()
print(f"{my_info=}")

tracer = LineWorksTracer(works=works)
tracer.add_trace_func(PacketType.PUBLISH, receive_publish_packet)
tracer.trace()

sample_usage

sample_usage_2

sample_usage_3

Contributors

GitHub Actions

Linter & Formatter

  • ruff
  • mypy

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

line_works_sdk-3.9.dev202510170103.tar.gz (59.4 kB view details)

Uploaded Source

Built Distribution

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

line_works_sdk-3.9.dev202510170103-py3-none-any.whl (100.5 kB view details)

Uploaded Python 3

File details

Details for the file line_works_sdk-3.9.dev202510170103.tar.gz.

File metadata

File hashes

Hashes for line_works_sdk-3.9.dev202510170103.tar.gz
Algorithm Hash digest
SHA256 b5f222324a723becee2f91723d999ad68755a43940a2d05369a4e599726014ae
MD5 b49bf6f5f40e03b8046086e62c0b6f66
BLAKE2b-256 619a0fa2ef6e97a0e89ab94091983cb8faae1a380c3b16b7d575da87ff476669

See more details on using hashes here.

File details

Details for the file line_works_sdk-3.9.dev202510170103-py3-none-any.whl.

File metadata

File hashes

Hashes for line_works_sdk-3.9.dev202510170103-py3-none-any.whl
Algorithm Hash digest
SHA256 2b1453821be92d8053e6ceffd8d2b7ab1743dbd2866eaf0989939d2f3ca410d2
MD5 bd864927da918a5eb60179a5d54e74ac
BLAKE2b-256 8ff92ce07b74ee7e0e1f71cb0ea4faac57ca97c67f21282444046c26ebcf83e2

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