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

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-2.0.0.tar.gz (27.2 kB view details)

Uploaded Source

Built Distribution

rcs_pydantic-2.0.0-py3-none-any.whl (26.6 kB view details)

Uploaded Python 3

File details

Details for the file rcs_pydantic-2.0.0.tar.gz.

File metadata

  • Download URL: rcs_pydantic-2.0.0.tar.gz
  • Upload date:
  • Size: 27.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1018-azure

File hashes

Hashes for rcs_pydantic-2.0.0.tar.gz
Algorithm Hash digest
SHA256 ac85d3406bd0b1e44ad414719b071f5ae40c62a5395224d28a05139f4029a86f
MD5 be33b52dd1d08be4a4a16d12939d7307
BLAKE2b-256 a2df137c48aee8ecf97c0e46eb9de54a4400d9bc44241a98f13dc3aa5976e307

See more details on using hashes here.

File details

Details for the file rcs_pydantic-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: rcs_pydantic-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1018-azure

File hashes

Hashes for rcs_pydantic-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 33792c27c7dfb780fd1765f5dc3477a62ef51ae4e3e7b73243c0fbfdabb28496
MD5 89d5b670318438feeaae039c22ef1ed8
BLAKE2b-256 964d1c8a6d0e4eaadce9b115ee198452619f542b2eb24c987483b74bacd7c555

See more details on using hashes here.

Supported by

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