Node.js를 사용하여 텔레그램 채널에 메세지를 보내는 예제입니다.
<텔레그램 봇 토큰>과 <채널 ID> 부분은 아래 글에서 설명했던 값으로 바꿔줍니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | var http = require( "https" ); var options = { hostname: 'api.telegram.org' , path: '/bot<텔레그램 봇 토큰>/sendMessage' , method: 'POST' , headers: { 'Content-Type' : 'application/json' , } }; var req = http.request(options, function (res) { console.log( 'Status: ' + res.statusCode); console.log( 'Headers: ' + JSON.stringify(res.headers)); res.setEncoding( 'utf8' ); res.on( 'data' , function (body) { console.log( 'Body: ' + body); }); }); req.on( 'error' , function (e) { console.log( 'problem with request: ' + e.message); }); req.write( '{"chat_id": "@<채널 ID>", "text": "test string"}' ); req.end(); |
참고 글
- [Node.js] HTTP 요청하기 (http 모듈 사용)
'1. 연구 모듈 > 텔레그램' 카테고리의 다른 글
텔레그램 봇으로 채널 포스팅 - 6. Python 사용 예제 (2) (1) | 2017.03.21 |
---|---|
텔레그램 봇으로 채널 포스팅 - 5. Clojure 사용 예제 (1) (0) | 2016.12.14 |
텔레그램 봇으로 채널 포스팅 - 4. Python 사용 예제 (1) (1) | 2016.12.13 |
텔레그램 봇으로 채널 포스팅 - 3. Node.js 사용 예제 (2) (0) | 2016.10.06 |
텔레그램 봇으로 채널 포스팅 - 1. 준비 작업 (3) | 2016.08.31 |