Skip to main content

RCS-PYDANTIC

Test Coverage Package version Supported Python versions

Introduce

한국 통신사 rcs 를 위한 pydantic 모델

fastapi 또는 django-ninja 와 함께 사용할 때 유용합니다.

Installation

pip install rcs-pydantic

Dependency

  • python3.x (3.8 이상)
  • pydantic

Quick start

from rcs_pydantic import MessageInfo, RcsMessage

message_info = {
    "replyId": "B01RDSFR.KcNNLk67ui.FDSAF432153214",
    "eventType":"newUser",
    "displayText": "안녕",
    "userContact":"01012341234",
    "chatbotId":"0212351235",
    "timestamp": "2020-03-03T04:43:55.867+09"
}

rcs = {
    "message_base_id": "SS000000",
    "service_type": "RCSSMS",
    "agency_id": "<str: agency_id>",
    "body": {
        "title": "타이틀",
        "description": "일반 RCSSMS 테스트 메시지 입니다."
    }
}


rcs_message = RcsMessage(message_info=MessageInfo(**message_info), **rcs)
>>> print(rcs_message.send_info)
common=CommonInfo(
    msgId='4be0072f-0f05-4b3a-adc8-90d7ef309c53',
    userContact='01012341234',
    scheduleType=<ScheduleTypeEnum.IMMEDIATE: 0>,
    msgServiceType=<MessageServiceTypeEnum.RCS: 'rcs'>
)
rcs=RcsInfo(
    chatbotId='0212351235',
    agencyId='<str: agency_id>',
    messagebaseId='SS000000',
    serviceType=<ServiceTypeEnum.SMS: 'RCSSMS'>,
    expiryOption=<ExpiryOptionEnum.AFTER_SETTING_TIMES: 2>,
    header=<HeaderEnum.NOT_ADVERTISE: '0'>,
    copyAllowed=True,
    body=RcsSMSBody(title='타이틀', description='일반 RCSSMS 테스트 메시지 입니다.'),
    agencyKey='<str: agency_key>'
    brandKey='<str: brand_key>'
)
>>>

제공되는 항목

국내 통신사 RCS 문서에서 제공되는 모든 데이터를 pydandic 모델로써 지원합니다.

제공되는 데이터 pydantic 모델

RcsSMSBody
RcsLMSBody
RcsMMSBody
RcsCHATBody
RcsSMSCarouselBody
RcsLMSCarouselBody
RcsMMSCarouselBody
RcsCHATCarouselBody
LocationInfo
ShowLocationInfo
OpenUrlInfo
CreateCalendarEventInfo
CopyToClipboardInfo
ComposeTextMessageInfo
DialPhoneNumberInfo
UrlActionInfo
LocalBrowserActionInfo
MapActionInfo
CalendarActionInfo
ClipboardActionInfo
ComposeActionInfo
DialActionInfo
PostbackInfo
ActionInfo
SuggestionInfo
ButtonInfo
CommonInfo
RcsInfo
LegacyInfo
StatusInfo
QuerystatusInfo
ErrorInfo
ResponseErrorInfo
ResponseInfo
TextMessageInfo
FileMessageInfo
GeolocationPushMessage
UserLocationInfo
MessageInfo
SendInfo
TokenInfo

제공되는 데이터 관련 Enum

EventTypeEnum
RCSMessageEnum
MessageEnum
MessageStatusEnum
MnoInfoEnum
BillEnum
MessageServiceTypeEnum
ServiceTypeEnum
LegacyServiceTypeEnum
ScheduleTypeEnum
ExpiryOptionEnum
HeaderEnum
ActionEnum

제공되는 에러 코드 Enum

ErrorCodeEnum
MaaPErrorCodeEnum
RcsBizCenterErrorCodeEnum
KTErrorCodeEnum
LegacyErrorCodeEnum

Features

RcsMessage

RcsMessage 클래스는 서버로 수신된 MessageInfo 메세지 모델을 기반으로 메세지 전송을 위한 SendInfo 모델을 만듭니다.

from rcs_pydantic import MessageInfo, RcsMessage

message_info = {
    "replyId": "B01RDSFR.KcNNLk67ui.FDSAF432153214",
    "eventType":"newUser",
    "displayText": "안녕",
    "userContact":"01012341234",
    "chatbotId":"0212351235",
    "timestamp": "2020-03-03T04:43:55.867+09"
}

rcs = {
    "message_base_id": "SS000000",
    "service_type": "RCSSMS",
    "agency_id": "<str: agency_id>",
    "body": {
        "title": "타이틀",
        "description": "일반 RCSSMS 테스트 메시지 입니다."
    }
}


rcs_message = RcsMessage(message_info=MessageInfo(**message_info), **rcs)

MessageException

MessageException 예외 클래스는 제공되는 모든 에러 코드 Enum 을 포함하는 예외 클래스입니다.

다음과 같이 여러 Enum 코드중 한가지를 메세지로 반환합니다.

from rcs_pydantic.errors import ErrorCodeEnum
from rcs_pydantic.exceptions import MessageException
try:
    raise MessageException(ErrorCodeEnum.MISSING_AUTHORIZATION_HEADER.value[0])
except MessageException as e:
    print(f"ERROR MESSAGE: {e}")

ERROR MESSAGE: Valid access token in Authorization header is required for RESTful API calls.
>>>

다음과 같이 has_value 를 통해 특정 Enum 에 포함된 에러인지 확인할 수 있습니다.

>>> from rcs_pydantic.errors import ErrorCodeEnum
... ErrorCodeEnum.has_value(40003)
True
>>> ErrorCodeEnum.has_value(11111)
False

Contribution

이 프로젝트는 기여를 환영합니다!

패치를 제출하기 전에 issue 티켓을 먼저 제출해주세요.

Pull request 는 main 브랜치로 머지되며 항상 사용 가능한 상태로 유지해야 합니다.

모든 테스트 코드를 통과한 뒤 리뷰한 후 머지됩니다.

Metadata

Release files for rcs-pydantic 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rcs-pydantic 2.0.0
File Size Uploaded Provenance
rcs_pydantic-2.0.0.tar.gz 27.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for rcs-pydantic 2.0.0
File Interpreter ABI Platform
rcs_pydantic-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 53.8 kB

Release files / rcs_pydantic-2.0.0.tar.gz

Download URL rcs_pydantic-2.0.0.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ac85d3406bd0b1e44ad414719b071f5ae40c62a5395224d28a05139f4029a86f
BLAKE2b-256 checksum
How to use checksums
a2df137c48aee8ecf97c0e46eb9de54a4400d9bc44241a98f13dc3aa5976e307
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1018-azure

Release files / rcs_pydantic-2.0.0-py3-none-any.whl

Download URL rcs_pydantic-2.0.0-py3-none-any.whl
Size 26.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
33792c27c7dfb780fd1765f5dc3477a62ef51ae4e3e7b73243c0fbfdabb28496
BLAKE2b-256 checksum
How to use checksums
964d1c8a6d0e4eaadce9b115ee198452619f542b2eb24c987483b74bacd7c555
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1018-azure

Security for rcs-pydantic 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page