Skip to main content

No project description provided

Project description

RCS-PYDANTIC

Test Coverage Package version Supported Python versions

Introduce

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

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

Installation

pip install rcs-pydantic-automata

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 브랜치로 머지되며 항상 사용 가능한 상태로 유지해야 합니다.

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

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

rcs_pydantic_automata-1.0.0.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

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

rcs_pydantic_automata-1.0.0-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file rcs_pydantic_automata-1.0.0.tar.gz.

File metadata

  • Download URL: rcs_pydantic_automata-1.0.0.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.12 Linux/6.11.0-1012-azure

File hashes

Hashes for rcs_pydantic_automata-1.0.0.tar.gz
Algorithm Hash digest
SHA256 254b9f4e626390e89b1b1ad3dbd5de5f792b2c9ac13484c778a3f2cf4be8f8e1
MD5 26c8328361cd64d5ddb75b0c3c3c7250
BLAKE2b-256 e95a279c270716afbf95629ef4e6931b7c00a66d8adaf04d1ad6cc5b7c4ad509

See more details on using hashes here.

File details

Details for the file rcs_pydantic_automata-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: rcs_pydantic_automata-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.11.12 Linux/6.11.0-1012-azure

File hashes

Hashes for rcs_pydantic_automata-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa3770e8f0037678012f4d91730e6eec16aae885a854423cfef22e82d7ce9471
MD5 23a55797f6483cc90fc4b5e06eef3ecc
BLAKE2b-256 1831b79a921697c250299bc0949ed5cd773ebb1d7dd9ec0a63bfbfff3d89ff97

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