# RCS-PYDANTIC
<p align="center">
<a href="https://github.com/xncbf/rcs-pydantic/actions?query=workflow%3ATests+event%3Apush+branch%3Amain" target="_blank">
<img src="https://github.com/xncbf/rcs-pydantic/workflows/Tests/badge.svg?event=push&branch=main" alt="Test">
</a>
<a href="https://codecov.io/gh/xncbf/rcs-pydantic" target="_blank">
<img src="https://img.shields.io/codecov/c/github/xncbf/rcs-pydantic?color=%2334D058" alt="Coverage">
</a>
<a href="https://pypi.org/project/rcs-pydantic" target="_blank">
<img src="https://img.shields.io/pypi/v/rcs-pydantic?color=%2334D058&label=pypi%20package" alt="Package version">
</a>
<a href="https://pypi.org/project/rcs-pydantic" target="_blank">
<img src="https://img.shields.io/pypi/pyversions/rcs-pydantic.svg?color=%2334D058" alt="Supported Python versions">
</a>
</p>
- [RCS-PYDANTIC](#rcs-pydantic)
- [Introduce](#introduce)
- [Installation](#installation)
- [Dependency](#dependency)
- [Quick start](#quick-start)
- [제공되는 항목](#제공되는-항목)
- [제공되는 데이터 pydantic 모델](#제공되는-데이터-pydantic-모델)
- [제공되는 데이터 관련 Enum](#제공되는-데이터-관련-enum)
- [제공되는 에러 코드 Enum](#제공되는-에러-코드-enum)
- [Features](#features)
- [RcsMessage](#rcsmessage)
- [MessageException](#messageexception)
- [Contribution](#contribution)
## Introduce
한국 통신사 rcs 를 위한 pydantic 모델
[fastapi](https://github.com/tiangolo/fastapi) 또는 [django-ninja](https://github.com/vitalik/django-ninja) 와 함께 사용할 때 유용합니다.
## Installation
```sh
pip install rcs-pydantic
```
## Dependency
- python3.x (3.8 이상)
- pydantic
## Quick start
```py
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)
```
```sh
>>> 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 모델
```python
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
```python
EventTypeEnum
RCSMessageEnum
MessageEnum
MessageStatusEnum
MnoInfoEnum
BillEnum
MessageServiceTypeEnum
ServiceTypeEnum
LegacyServiceTypeEnum
ScheduleTypeEnum
ExpiryOptionEnum
HeaderEnum
ActionEnum
```
### 제공되는 에러 코드 Enum
```python
ErrorCodeEnum
MaaPErrorCodeEnum
RcsBizCenterErrorCodeEnum
KTErrorCodeEnum
LegacyErrorCodeEnum
```
## Features
### RcsMessage
`RcsMessage` 클래스는 서버로 수신된 `MessageInfo` 메세지 모델을 기반으로 메세지 전송을 위한 `SendInfo` 모델을 만듭니다.
```py
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 코드중 한가지를 메세지로 반환합니다.
```python
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` 에 포함된 에러인지 확인할 수 있습니다.
```python
>>> from rcs_pydantic.errors import ErrorCodeEnum
... ErrorCodeEnum.has_value(40003)
True
>>> ErrorCodeEnum.has_value(11111)
False
```
## Contribution
이 프로젝트는 기여를 환영합니다!
패치를 제출하기 전에 issue 티켓을 먼저 제출해주세요.
Pull request 는 `main` 브랜치로 머지되며 항상 사용 가능한 상태로 유지해야 합니다.
모든 테스트 코드를 통과한 뒤 리뷰한 후 머지됩니다.
Raw data
{
"_id": null,
"home_page": "https://github.com/xncbf/rcs-pydantic",
"name": "rcs-pydantic",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "pydantic,rcs,fastapi",
"author": "xncbf",
"author_email": "xncbf12@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/a2/df/137c48aee8ecf97c0e46eb9de54a4400d9bc44241a98f13dc3aa5976e307/rcs_pydantic-2.0.0.tar.gz",
"platform": null,
"description": "# RCS-PYDANTIC\n\n<p align=\"center\">\n<a href=\"https://github.com/xncbf/rcs-pydantic/actions?query=workflow%3ATests+event%3Apush+branch%3Amain\" target=\"_blank\">\n <img src=\"https://github.com/xncbf/rcs-pydantic/workflows/Tests/badge.svg?event=push&branch=main\" alt=\"Test\">\n</a>\n<a href=\"https://codecov.io/gh/xncbf/rcs-pydantic\" target=\"_blank\">\n <img src=\"https://img.shields.io/codecov/c/github/xncbf/rcs-pydantic?color=%2334D058\" alt=\"Coverage\">\n</a>\n<a href=\"https://pypi.org/project/rcs-pydantic\" target=\"_blank\">\n <img src=\"https://img.shields.io/pypi/v/rcs-pydantic?color=%2334D058&label=pypi%20package\" alt=\"Package version\">\n</a>\n<a href=\"https://pypi.org/project/rcs-pydantic\" target=\"_blank\">\n <img src=\"https://img.shields.io/pypi/pyversions/rcs-pydantic.svg?color=%2334D058\" alt=\"Supported Python versions\">\n</a>\n</p>\n\n- [RCS-PYDANTIC](#rcs-pydantic)\n - [Introduce](#introduce)\n - [Installation](#installation)\n - [Dependency](#dependency)\n - [Quick start](#quick-start)\n - [\uc81c\uacf5\ub418\ub294 \ud56d\ubaa9](#\uc81c\uacf5\ub418\ub294-\ud56d\ubaa9)\n - [\uc81c\uacf5\ub418\ub294 \ub370\uc774\ud130 pydantic \ubaa8\ub378](#\uc81c\uacf5\ub418\ub294-\ub370\uc774\ud130-pydantic-\ubaa8\ub378)\n - [\uc81c\uacf5\ub418\ub294 \ub370\uc774\ud130 \uad00\ub828 Enum](#\uc81c\uacf5\ub418\ub294-\ub370\uc774\ud130-\uad00\ub828-enum)\n - [\uc81c\uacf5\ub418\ub294 \uc5d0\ub7ec \ucf54\ub4dc Enum](#\uc81c\uacf5\ub418\ub294-\uc5d0\ub7ec-\ucf54\ub4dc-enum)\n - [Features](#features)\n - [RcsMessage](#rcsmessage)\n - [MessageException](#messageexception)\n - [Contribution](#contribution)\n\n## Introduce\n\n\ud55c\uad6d \ud1b5\uc2e0\uc0ac rcs \ub97c \uc704\ud55c pydantic \ubaa8\ub378\n\n[fastapi](https://github.com/tiangolo/fastapi) \ub610\ub294 [django-ninja](https://github.com/vitalik/django-ninja) \uc640 \ud568\uaed8 \uc0ac\uc6a9\ud560 \ub54c \uc720\uc6a9\ud569\ub2c8\ub2e4.\n\n## Installation\n\n```sh\npip install rcs-pydantic\n```\n\n## Dependency\n\n- python3.x (3.8 \uc774\uc0c1)\n- pydantic\n\n## Quick start\n\n```py\nfrom rcs_pydantic import MessageInfo, RcsMessage\n\nmessage_info = {\n \"replyId\": \"B01RDSFR.KcNNLk67ui.FDSAF432153214\",\n \"eventType\":\"newUser\",\n \"displayText\": \"\uc548\ub155\",\n \"userContact\":\"01012341234\",\n \"chatbotId\":\"0212351235\",\n \"timestamp\": \"2020-03-03T04:43:55.867+09\"\n}\n\nrcs = {\n \"message_base_id\": \"SS000000\",\n \"service_type\": \"RCSSMS\",\n \"agency_id\": \"<str: agency_id>\",\n \"body\": {\n \"title\": \"\ud0c0\uc774\ud2c0\",\n \"description\": \"\uc77c\ubc18 RCSSMS \ud14c\uc2a4\ud2b8 \uba54\uc2dc\uc9c0 \uc785\ub2c8\ub2e4.\"\n }\n}\n\n\nrcs_message = RcsMessage(message_info=MessageInfo(**message_info), **rcs)\n```\n\n```sh\n>>> print(rcs_message.send_info)\ncommon=CommonInfo(\n msgId='4be0072f-0f05-4b3a-adc8-90d7ef309c53',\n userContact='01012341234',\n scheduleType=<ScheduleTypeEnum.IMMEDIATE: 0>,\n msgServiceType=<MessageServiceTypeEnum.RCS: 'rcs'>\n)\nrcs=RcsInfo(\n chatbotId='0212351235',\n agencyId='<str: agency_id>',\n messagebaseId='SS000000',\n serviceType=<ServiceTypeEnum.SMS: 'RCSSMS'>,\n expiryOption=<ExpiryOptionEnum.AFTER_SETTING_TIMES: 2>,\n header=<HeaderEnum.NOT_ADVERTISE: '0'>,\n copyAllowed=True,\n body=RcsSMSBody(title='\ud0c0\uc774\ud2c0', description='\uc77c\ubc18 RCSSMS \ud14c\uc2a4\ud2b8 \uba54\uc2dc\uc9c0 \uc785\ub2c8\ub2e4.'),\n agencyKey='<str: agency_key>'\n brandKey='<str: brand_key>'\n)\n>>>\n```\n\n## \uc81c\uacf5\ub418\ub294 \ud56d\ubaa9\n\n\uad6d\ub0b4 \ud1b5\uc2e0\uc0ac RCS \ubb38\uc11c\uc5d0\uc11c \uc81c\uacf5\ub418\ub294 \ubaa8\ub4e0 \ub370\uc774\ud130\ub97c pydandic \ubaa8\ub378\ub85c\uc368 \uc9c0\uc6d0\ud569\ub2c8\ub2e4.\n\n### \uc81c\uacf5\ub418\ub294 \ub370\uc774\ud130 pydantic \ubaa8\ub378\n\n```python\nRcsSMSBody\nRcsLMSBody\nRcsMMSBody\nRcsCHATBody\nRcsSMSCarouselBody\nRcsLMSCarouselBody\nRcsMMSCarouselBody\nRcsCHATCarouselBody\nLocationInfo\nShowLocationInfo\nOpenUrlInfo\nCreateCalendarEventInfo\nCopyToClipboardInfo\nComposeTextMessageInfo\nDialPhoneNumberInfo\nUrlActionInfo\nLocalBrowserActionInfo\nMapActionInfo\nCalendarActionInfo\nClipboardActionInfo\nComposeActionInfo\nDialActionInfo\nPostbackInfo\nActionInfo\nSuggestionInfo\nButtonInfo\nCommonInfo\nRcsInfo\nLegacyInfo\nStatusInfo\nQuerystatusInfo\nErrorInfo\nResponseErrorInfo\nResponseInfo\nTextMessageInfo\nFileMessageInfo\nGeolocationPushMessage\nUserLocationInfo\nMessageInfo\nSendInfo\nTokenInfo\n```\n\n### \uc81c\uacf5\ub418\ub294 \ub370\uc774\ud130 \uad00\ub828 Enum\n\n```python\nEventTypeEnum\nRCSMessageEnum\nMessageEnum\nMessageStatusEnum\nMnoInfoEnum\nBillEnum\nMessageServiceTypeEnum\nServiceTypeEnum\nLegacyServiceTypeEnum\nScheduleTypeEnum\nExpiryOptionEnum\nHeaderEnum\nActionEnum\n```\n\n### \uc81c\uacf5\ub418\ub294 \uc5d0\ub7ec \ucf54\ub4dc Enum\n\n```python\nErrorCodeEnum\nMaaPErrorCodeEnum\nRcsBizCenterErrorCodeEnum\nKTErrorCodeEnum\nLegacyErrorCodeEnum\n```\n\n## Features\n\n### RcsMessage\n\n`RcsMessage` \ud074\ub798\uc2a4\ub294 \uc11c\ubc84\ub85c \uc218\uc2e0\ub41c `MessageInfo` \uba54\uc138\uc9c0 \ubaa8\ub378\uc744 \uae30\ubc18\uc73c\ub85c \uba54\uc138\uc9c0 \uc804\uc1a1\uc744 \uc704\ud55c `SendInfo` \ubaa8\ub378\uc744 \ub9cc\ub4ed\ub2c8\ub2e4.\n\n```py\nfrom rcs_pydantic import MessageInfo, RcsMessage\n\nmessage_info = {\n \"replyId\": \"B01RDSFR.KcNNLk67ui.FDSAF432153214\",\n \"eventType\":\"newUser\",\n \"displayText\": \"\uc548\ub155\",\n \"userContact\":\"01012341234\",\n \"chatbotId\":\"0212351235\",\n \"timestamp\": \"2020-03-03T04:43:55.867+09\"\n}\n\nrcs = {\n \"message_base_id\": \"SS000000\",\n \"service_type\": \"RCSSMS\",\n \"agency_id\": \"<str: agency_id>\",\n \"body\": {\n \"title\": \"\ud0c0\uc774\ud2c0\",\n \"description\": \"\uc77c\ubc18 RCSSMS \ud14c\uc2a4\ud2b8 \uba54\uc2dc\uc9c0 \uc785\ub2c8\ub2e4.\"\n }\n}\n\n\nrcs_message = RcsMessage(message_info=MessageInfo(**message_info), **rcs)\n```\n\n### MessageException\n\n`MessageException` \uc608\uc678 \ud074\ub798\uc2a4\ub294 \uc81c\uacf5\ub418\ub294 \ubaa8\ub4e0 \uc5d0\ub7ec \ucf54\ub4dc Enum \uc744 \ud3ec\ud568\ud558\ub294 \uc608\uc678 \ud074\ub798\uc2a4\uc785\ub2c8\ub2e4.\n\n\ub2e4\uc74c\uacfc \uac19\uc774 \uc5ec\ub7ec Enum \ucf54\ub4dc\uc911 \ud55c\uac00\uc9c0\ub97c \uba54\uc138\uc9c0\ub85c \ubc18\ud658\ud569\ub2c8\ub2e4.\n\n```python\nfrom rcs_pydantic.errors import ErrorCodeEnum\nfrom rcs_pydantic.exceptions import MessageException\ntry:\n raise MessageException(ErrorCodeEnum.MISSING_AUTHORIZATION_HEADER.value[0])\nexcept MessageException as e:\n print(f\"ERROR MESSAGE: {e}\")\n\nERROR MESSAGE: Valid access token in Authorization header is required for RESTful API calls.\n>>>\n```\n\n\ub2e4\uc74c\uacfc \uac19\uc774 `has_value` \ub97c \ud1b5\ud574 \ud2b9\uc815 `Enum` \uc5d0 \ud3ec\ud568\ub41c \uc5d0\ub7ec\uc778\uc9c0 \ud655\uc778\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.\n\n```python\n>>> from rcs_pydantic.errors import ErrorCodeEnum\n... ErrorCodeEnum.has_value(40003)\nTrue\n>>> ErrorCodeEnum.has_value(11111)\nFalse\n```\n\n## Contribution\n\n\uc774 \ud504\ub85c\uc81d\ud2b8\ub294 \uae30\uc5ec\ub97c \ud658\uc601\ud569\ub2c8\ub2e4!\n\n\ud328\uce58\ub97c \uc81c\ucd9c\ud558\uae30 \uc804\uc5d0 issue \ud2f0\ucf13\uc744 \uba3c\uc800 \uc81c\ucd9c\ud574\uc8fc\uc138\uc694.\n\nPull request \ub294 `main` \ube0c\ub79c\uce58\ub85c \uba38\uc9c0\ub418\uba70 \ud56d\uc0c1 \uc0ac\uc6a9 \uac00\ub2a5\ud55c \uc0c1\ud0dc\ub85c \uc720\uc9c0\ud574\uc57c \ud569\ub2c8\ub2e4.\n\n\ubaa8\ub4e0 \ud14c\uc2a4\ud2b8 \ucf54\ub4dc\ub97c \ud1b5\uacfc\ud55c \ub4a4 \ub9ac\ubdf0\ud55c \ud6c4 \uba38\uc9c0\ub429\ub2c8\ub2e4.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "",
"version": "2.0.0",
"project_urls": {
"Homepage": "https://github.com/xncbf/rcs-pydantic",
"Repository": "https://github.com/xncbf/rcs-pydantic"
},
"split_keywords": [
"pydantic",
"rcs",
"fastapi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "964d1c8a6d0e4eaadce9b115ee198452619f542b2eb24c987483b74bacd7c555",
"md5": "89d5b670318438feeaae039c22ef1ed8",
"sha256": "33792c27c7dfb780fd1765f5dc3477a62ef51ae4e3e7b73243c0fbfdabb28496"
},
"downloads": -1,
"filename": "rcs_pydantic-2.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "89d5b670318438feeaae039c22ef1ed8",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 26597,
"upload_time": "2024-01-22T08:41:52",
"upload_time_iso_8601": "2024-01-22T08:41:52.733211Z",
"url": "https://files.pythonhosted.org/packages/96/4d/1c8a6d0e4eaadce9b115ee198452619f542b2eb24c987483b74bacd7c555/rcs_pydantic-2.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a2df137c48aee8ecf97c0e46eb9de54a4400d9bc44241a98f13dc3aa5976e307",
"md5": "be33b52dd1d08be4a4a16d12939d7307",
"sha256": "ac85d3406bd0b1e44ad414719b071f5ae40c62a5395224d28a05139f4029a86f"
},
"downloads": -1,
"filename": "rcs_pydantic-2.0.0.tar.gz",
"has_sig": false,
"md5_digest": "be33b52dd1d08be4a4a16d12939d7307",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 27177,
"upload_time": "2024-01-22T08:41:54",
"upload_time_iso_8601": "2024-01-22T08:41:54.336958Z",
"url": "https://files.pythonhosted.org/packages/a2/df/137c48aee8ecf97c0e46eb9de54a4400d9bc44241a98f13dc3aa5976e307/rcs_pydantic-2.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-01-22 08:41:54",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "xncbf",
"github_project": "rcs-pydantic",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "rcs-pydantic"
}