1. 연구 모듈/텔레그램
텔레그램 봇으로 채널 포스팅 - 5. Clojure 사용 예제 (1)
사용자-1
2016. 12. 14. 06:02
사전 준비 사항
clj-http 모듈 사용을 위해서 project.clj 파일의 dependencies 부분에 아래와 같이 추가해준다. (버전은 참고사이트에서 최신 버전을 확인하자)
(defproject projectname "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.6.0"]
[clj-http "2.2.0"]])
채널 포스팅
Clojure를 사용하여 텔레그램 채널에 메세지를 보내는 예제입니다.
<텔레그램 봇 토큰>과 <채널 ID> 부분은 아래 글에서 설명했던 값으로 바꿔줍니다.
(require '[clj-http.client :as client])
(println (client/post "https://api.telegram.org//bot<텔레그램 봇 토큰>/sendMessage"
{:body "{\"chat_id\": \"@<채널 ID>\", \"text\": \"test string\"}"
:headers {"Content-Type" "application/json"}}))
(println "done")
참고 글
참고 사이트
<테스트 버전> Eclipse 버전 : Mars CCW 버전 : 0.35.0.STABLE001 Leiningen 버전 : 1.0.0