# 7. 댓글 푸시를 만들고 싶어요.

{% hint style="info" %}
먼저 [푸시 기초 클래스](/main/class/undefined/2.md)를 보시면 좋아요.

내가 쓴 글에 댓글, 좋아요 푸시 알람은 패키지를 활용해 보세요!

글 > 그림 순서로 설명했어요.
{% endhint %}

댓글, 좋아요, 조회 등 다양한 정보들이 **데이터 로그, 신고 관리(\_docTimeline)** 메타에 저장돼요.

이 메타를 활용해 푸시 로직을 만들어 볼게요.

먼저 관리자 웹 > 로직 설정에서 푸시 로직을 하나 만들어요.

## If When

* 등록할 때

### Where

* 데이터 로그, 신고 관리(\_docTimeline)

<figure><img src="/files/FMr8zzWEREomQ9VzQAEX" alt="" width="324"><figcaption></figcaption></figure>

## Condition

### Data condition

* And 조건 1 *(해설 : 새 댓글의 형식이 댓글일 때)*
  * newDocument.component
  * 같을 때
  * \_reply
* And 조건 2 *(해설 : 새 댓글이 달린 곳이(메타가) 커뮤니티 일 때)*
  * newDocument.collectionName
  * 같을 때
  * community

### New data Query

#### flows

* **query** *(해설 : 새 댓글의 documentId와 데이터 로그, 신고 관리 메타의 \_id와 일치하는 것을 찾기)*
  * 컬렉션 명 : 데이터 로그, 신고 관리(\_docTimeline)
  * 조회 조건
    * And 조건 *(해설 : 새 댓글의 documentId와 같은 ID)*
      * ID
      * 같을 때
      * newDocument.documentId *(해설 : documentId는 댓글이 달린 글의 id)*
* **setValue** *(해설 : query로 가져온 데이터의 첫 번째를 reply라는 키 값에 정의)*
  * reply
  * 원하는 순번의 리스트 데이터를 바인딩
    * 데이터를 추출할 리스트 데이터를 : tmpDocument.findDocument
    * 몇 번째 데이터를 추출하시겠습니까? : 0
* **if** *(해설 : reply라는 데이터가 없으면 참, 데이터가 있으면 거짓으로 예외 처리(=로직 종료))*
  * And 조건
    * Method : 빈 값일 때
    * Key : tmpDocument.reply
  * \#ifTrue&#x20;
  * \#ifFalse&#x20;
    * @returnException&#x20;
      * Message : 답글
      * Code : -1
* **해설**
  * 답글도 \_reply 형식으로 데이터 로그, 신고 관리 (docTimeline) 메타에 저장돼요. 따라서 댓글일 때만 푸시를 보내기 위해 이렇게 설정하는 거에요.

<figure><img src="/files/pJNJBbOMiC95oNq5Svjs" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/bY7X9UTksIqQ3mPLJpBz" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/DR3Zs0oQ4sKTuRHc8aDa" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/jj7zbDMS6ms8iIbLCgfv" alt=""><figcaption></figcaption></figure>

## Then

푸시 알람을 발송

### To do

* 메시지 제목 ([참고 가이드](/main/guide/develop_app/command-execute-function/create-logic/flow_option/sendpushnotifications.md))
* 메시지 내용
* 전송 대상 : 푸시 알람을 받을 유저 \_id
  * parentDocument.\_createUse&#x72;*.\_*&#x69;d *(해설 : parentDocument는 댓글이 달린 글)*
* 메시지 타입 : 푸시를 눌렀을 때 이동할 화면 ([참고 가이드](/main/guide/faq/logic/6.md))
  * 아직은 **탭 이동**만 사용할 수 있어요.
  * 앱 푸시를 누르면 앱으로 접속하고 **푸시 히스토리**를 눌렀을 때 탭 이동을 해요.
* 이동할 탭 번호 : 메시지 타입이 **탭 이동**일 때 사용, 0이 첫 번째 탭
* 알람 소리
* Set after event : 후속 로직을 실행할 때 사용

<figure><img src="/files/JJ6xPTqU1TyTFhEBCA6Y" alt="" width="375"><figcaption></figcaption></figure>

이렇게 댓글 푸시 알람의 기본 틀을 살펴봤어요.

여기서 어떤 메타에서 글이 달렸을 때, 누구한테 푸시를 보낼지만 응용하면 되겠죠?

24.07.17 Jihwan


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ohmyapp.io/main/guide/faq/logic/7.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
