<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Telegram on</title><link>https://taetaetae.github.io/tags/telegram/</link><description>Recent content in Telegram on</description><generator>Hugo</generator><language>en</language><lastBuildDate>Sun, 28 Mar 2021 11:41:33 +0900</lastBuildDate><atom:link href="https://taetaetae.github.io/tags/telegram/index.xml" rel="self" type="application/rss+xml"/><item><title>공모주 알리미 개발 후기 - 2부</title><link>https://taetaetae.github.io/posts/public-offering-notice-2/</link><pubDate>Sun, 28 Mar 2021 11:41:33 +0900</pubDate><guid>https://taetaetae.github.io/posts/public-offering-notice-2/</guid><description>&lt;p>　﻿혹시 이 포스트를 처음 읽는 독자라면 &lt;a href="https://taetaetae.github.io/posts/public-offering-notice-1" rel="">지난 포스팅&lt;/a>을 읽고 오는 것을 추천한다. 정리하자면, 지난 포스트에서는 &lt;a href="https://t.me/PublicOfferingNotice" target="_blank" rel="noopener noreffer ">토이 프로젝트&lt;/a>를 시작하게 된 계기와, 어떤 식으로 만들지에 대한 설계. 그리고 데이터를 수집하는 과정에 대해 이야기했었다. 지난 포스팅에서 수집한 데이터를 이제 사용자들에게 알려주는 부분에 대해 정리하고자 한다.&lt;/p>
&lt;ul>
&lt;li>1부 : &lt;a href="https://taetaetae.github.io/posts/public-offering-notice-1" rel="">프로젝트 설계, 데이터 수집&lt;/a>&lt;/li>
&lt;li>2부 : &lt;a href="https://taetaetae.github.io/posts/public-offering-notice-2" rel="">수집한 데이터 알림 발송&lt;/a>&lt;/li>
&lt;li>3부 : &lt;a href="https://taetaetae.github.io/posts/public-offering-notice-3" rel="">서버 선정 및 릴리즈&lt;/a>&lt;/li>
&lt;/ul>
&lt;h2 id="데이터-정의">데이터 정의&lt;/h2>
&lt;p>　﻿java 라이브러리 중에 jsoup라는 것을 사용하여 웹사이트를 크롤링 하였고, 필요한 데이터를 파싱을 하였다. 아래는 &amp;lsquo;공모주&amp;rsquo;라는 자바 모델을 정의해 보았다. 이렇게 자바 &amp;lsquo;모델&amp;rsquo;로 정의를 하는 이유는 필요한 데이터가 무엇인지 다시 한번 정리를 하기 위함이기도 하고 map 같은 형태의 임시 변수(?)보다 더 직관적이기에 이후 코드를 작성하는데 가이드 역할의 효과도 얻을 수 있을 것 같았기 때문이다.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-java" data-lang="java">&lt;span class="line">&lt;span class="cl">&lt;span class="kd">public&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="kd">class&lt;/span> &lt;span class="nc">PublicOffering&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="p">{&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">name&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 종목명&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LocalDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">startDate&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 일정 시작일&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LocalDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">endDate&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 일정 마감일&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">LocalDate&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">listingDate&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 상장일&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">publicOfferingPrice&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 확정 공모가&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">expectedOfferingPrice&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 희망 공모가&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">List&lt;/span>&lt;span class="o">&amp;lt;&lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="o">&amp;gt;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">Underwriter&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 주간사&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">detailUrl&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 상세URL&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="kd">private&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">String&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="n">competitionRate&lt;/span>&lt;span class="p">;&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="c1">// 청약경쟁률&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="p">}&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>　﻿초기에는 위에서 정의한 모델처럼 공모주의 기본 정보만을 서비스해야겠다 생각했고, 관련 뉴스라든지 기타 추가적인 정보나 다른 분들의 요구 사항(?)들이 추가될 경우 점진적으로 설계를 하고서 확장시켜 나가는 방향으로 계획했다. 우선은 기능들이 부족하더라고 돌아가는 서비스를 만들고 싶었기에.&lt;/p>
&lt;figure>&lt;a class="lightgallery" href="https://taetaetae.github.io/images/public-offering-notice-2/agile.png" title="/images/public-offering-notice-2/agile.png" data-thumbnail="/images/public-offering-notice-2/agile.png" data-sub-html="&lt;h2>애자일 방법론! 출처 : https://m.blog.naver.com/keycosmos3/221267522930&lt;/h2>">
 &lt;img
 class="lazyload"
 src="https://taetaetae.github.io/svg/loading.min.svg"
 data-src="https://taetaetae.github.io/images/public-offering-notice-2/agile.png"
 data-srcset="https://taetaetae.github.io/images/public-offering-notice-2/agile.png, https://taetaetae.github.io/images/public-offering-notice-2/agile.png 1.5x, https://taetaetae.github.io/images/public-offering-notice-2/agile.png 2x"
 data-sizes="auto"
 alt="/images/public-offering-notice-2/agile.png" />
 &lt;/a>&lt;figcaption class="image-caption">애자일 방법론!&lt;br> 출처 : &lt;a href="https://m.blog.naver.com/keycosmos3/221267522930" target="_blank" rel="noopener noreffer ">https://m.blog.naver.com/keycosmos3/221267522930&lt;/a>&lt;/figcaption>
 &lt;/figure>
&lt;h2 id="텔레그램-봇채널-생성">텔레그램 봇/채널 생성&lt;/h2>
&lt;p>　﻿텔레그램 봇을 만드는 과정은 가볍게 검색을 해보면 너무나 쉽게 찾을 수 있지만, 보다 하나의 글 안에 모든 내용을 담고 싶어 텔레그램 봇을 만들고 → 텔레그램 채널을 만든 다음 → 텔레그램 봇을 이용해서 텔레그램 채널에 메시지를 보내는 걸 이야기해 보고자 한다.&lt;/p>
&lt;blockquote>
&lt;p>﻿아, 여기서 왜 꼭 &amp;lsquo;텔레그램&amp;rsquo;을 선택했는가에 대한 이유는 개인적으로 다른 메신저 (카카오톡, 라인 등)보다도 api를 활용하여 메시지를 보내는 과정이 단순하면서도 빠르고 쉽게 느껴졌기 때문이다. 혹시 텔레그램 이 아닌 다른 메신저로 보내달라는 요청이 있을 경우 그때 가서 고민해 보려 한다.&lt;/p>&lt;/blockquote>
&lt;ul>
&lt;li>텔레그램 봇 생성&lt;/li>
&lt;/ul>
&lt;p>　﻿먼저 텔레그램 메신저에서 &amp;lsquo;BotFather&amp;rsquo;라는 사용자를 찾고 &amp;lsquo;/start&amp;rsquo;를 누르면 아래와 같이 사용할 수 있는 명령어가 나온다.&lt;/p>
&lt;p>　﻿그다음 우리는 봇을 만들 것이기 때문에 &amp;lsquo;/newbot&amp;rsquo;을 누르고 봇의 이름을 작성하고 그 봇의 사용자 이름을 지정한다. &amp;lsquo;_bot&amp;rsquo;으로 끝나야 한다고 하기에 이름 뒤에 붙여서 만들면 그걸로 끝. 다음으로 친절하게 HTTP API를 사용할 수 있는 토큰이 발급되는데 이 토큰으로 봇을 컨트롤 가능하기 때문에 잘 간직하고(?) 있어야 한다.&lt;/p>
&lt;figure>&lt;a class="lightgallery" href="https://taetaetae.github.io/images/public-offering-notice-2/newbot.jpg" title="/images/public-offering-notice-2/newbot.jpg" data-thumbnail="/images/public-offering-notice-2/newbot.jpg" data-sub-html="&lt;h2>친절한 봇 아버지&lt;/h2>">
 &lt;img
 class="lazyload"
 src="https://taetaetae.github.io/svg/loading.min.svg"
 data-src="https://taetaetae.github.io/images/public-offering-notice-2/newbot.jpg"
 data-srcset="https://taetaetae.github.io/images/public-offering-notice-2/newbot.jpg, https://taetaetae.github.io/images/public-offering-notice-2/newbot.jpg 1.5x, https://taetaetae.github.io/images/public-offering-notice-2/newbot.jpg 2x"
 data-sizes="auto"
 alt="/images/public-offering-notice-2/newbot.jpg" width="70%" />
 &lt;/a>&lt;figcaption class="image-caption">친절한 봇 아버지&lt;/figcaption>
 &lt;/figure>
&lt;p>　﻿이후 해당 토큰을 이용해서 봇의 상태를 확인해보자. 아래의 url에 토큰 경로만 변경하여 입력하면 json 응답을 받을 수 있다.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-markdown" data-lang="markdown">&lt;span class="line">&lt;span class="cl">https://api.telegram.org/bot{token}/getUpdates
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">e.g. https://api.telegram.org/bot17...42:AAH...cQU/getUpdates
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;ul>
&lt;li>텔레그램 채널 생성&lt;/li>
&lt;/ul>
&lt;p>　﻿1:N으로 채널에 가입한 사람들에게 메시지를 일방적으로 보내야 하기 때문에 사용할 채널을 만들어 보자. 텔레그램 UI만 봐도 간단하게 생성하기 쉽게 되어있다. 더불어 이 채널에 메시지를 보내야 하기 때문에 위에서 만들었던 봇을 추가하고 관리자로 승격 시키자.&lt;/p>
&lt;figure>&lt;a class="lightgallery" href="https://taetaetae.github.io/images/public-offering-notice-2/newchannel.jpg" title="/images/public-offering-notice-2/newchannel.jpg" data-thumbnail="/images/public-offering-notice-2/newchannel.jpg" data-sub-html="&lt;h2>채널 생성 &amp;gt; 봇을 관리자로&lt;/h2>">
 &lt;img
 class="lazyload"
 src="https://taetaetae.github.io/svg/loading.min.svg"
 data-src="https://taetaetae.github.io/images/public-offering-notice-2/newchannel.jpg"
 data-srcset="https://taetaetae.github.io/images/public-offering-notice-2/newchannel.jpg, https://taetaetae.github.io/images/public-offering-notice-2/newchannel.jpg 1.5x, https://taetaetae.github.io/images/public-offering-notice-2/newchannel.jpg 2x"
 data-sizes="auto"
 alt="/images/public-offering-notice-2/newchannel.jpg" width="70%" />
 &lt;/a>&lt;figcaption class="image-caption">채널 생성 &amp;gt; 봇을 관리자로&lt;/figcaption>
 &lt;/figure>
&lt;ul>
&lt;li>﻿텔레그램 봇으로 텔레그램 채널에 메시지 보내기&lt;/li>
&lt;/ul>
&lt;p>　이 부분에서 약간 헤맸는데 결국 위에서 얻은 토큰과 채널의 특정 id를 알아야 메시지를 보낼 수 있다. 앞서 만들었던 채널에 아무 메시지나 작성을 하고 위에서 호출했던 &amp;lsquo;getUpdates&amp;rsquo; api를 다시 호출해보면 아래처럼 채널의 id를 구할 수 있게 된다.&lt;/p></description></item></channel></rss>