[G5] 텔레그램 API 연동/그누보드 쪽지 등록 시 PUSH 보내기 > 기술자료 | 해피정닷컴

[G5] 텔레그램 API 연동/그누보드 쪽지 등록 시 PUSH 보내기 > 기술자료

본문 바로가기

사이트 내 전체검색

[G5] 텔레그램 API 연동/그누보드 쪽지 등록 시 PUSH 보내기 > 기술자료

그누보드 [G5] 텔레그램 API 연동/그누보드 쪽지 등록 시 PUSH 보내기

페이지 정보


본문

https://sir.kr/g5_tip/11788 의 내용을 조금 수정하였습니다.


게시글 / 댓글 / 쪽지를 작성하면 텔레그램로 PUSH 하는 방법입니다.


1. 파일 구조
GNU5
   ├ adm
   │  ├ telegram
   │  │     ├ _common.php
   │  │     ├ telegram.lib.php
   │  │     └ telegram_setting.php
   │  └ admin.menu.990.php
   ├ bbs
   │   ├ memo_form_update.php // 메모 push
   │   ├ write_comment_update.php // 댓글 push
   │   └ write_update.php // 게시글 push
   └ extend
          └ telegram.extend.php


2. adm / admin.menu.990.php
<?php
$menu["menu990"] = array (
    array('990000', '추가기능', G5_ADMIN_URL.'/telegram/telegram_setting.php', 'ETC'),
    array('990660', '텔레그램', G5_ADMIN_URL.'/telegram/telegram_setting.php', 'telegram_setting'),
);
?>


3. adm / telegram / _common.php
<?php
define('G5_IS_ADMIN', true);
include_once ('../../common.php');
include_once(G5_ADMIN_PATH.'/admin.lib.php');
?>


4. adm / telegram / telegram.lib.php
<?php
if (!defined('_GNUBOARD_')) exit;

function curl_tele_sent($text){
    if($text){
        $g5['telegram_table'] = G5_TABLE_PREFIX.'telegram_setting'; // 텔레그램 테이블
        $row = sql_fetch(" select * from {$g5['telegram_table']} where idx = 1 ");
        
        $api_code = $row['bot_api_code'];
        $chat_id  = $row['bot_chat_id'];
        
        if($api_code && $chat_id){
            $ch = curl_init();
            $curl_url = "https://api.telegram.org/bot{$api_code}/sendMessage?chat_id={$chat_id}&text={$text}";
            @curl_setopt($ch, CURLOPT_URL, $curl_url);
            @curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);     
            @curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);      
            @curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);   
            $exec = curl_exec($ch);
            echo " ";
        }
        echo " ";
    }
}
?>


5. adm / telegram / telegram_setting.php
<?php
include_once('./_common.php');
$sub_menu = '990660';
//$g5['telegram_table'] = G5_TABLE_PREFIX.'telegram_setting'; // 텔레그램 테이블

//내용(컨텐츠)정보 테이블이 있는지 검사한다.
if(!sql_query(" DESCRIBE {$g5['telegram_table']} ", false)) {
    sql_query(" CREATE TABLE IF NOT EXISTS `{$g5['telegram_table']}` (
        `idx` int(11) NOT NULL,
        `bot_api_code` varchar(255) NOT NULL,
        `bot_chat_id` varchar(255) NOT NULL
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ", true);
    //) ENGINE=InnoDB DEFAULT CHARSET=utf8 ", true);
    //) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC ", true);
    
    sql_query(" ALTER TABLE `g5_telegram_setting` ADD UNIQUE KEY `idx` (`idx`); ", true);
    
    // 내용관리 생성
    sql_query(" insert into `{$g5['telegram_table']}` (idx, bot_api_code, bot_chat_id) values ('1', '', '') " );
}

include_once('./_common.php');
auth_check($auth[$sub_menu], 'r');
$g5['title'] = '텔레그램 플러그인 기본설정';
include_once(G5_ADMIN_PATH.'/admin.head.php');

$row = sql_fetch(" select bot_api_code, bot_chat_id from {$g5['telegram_table']} where idx = 1 ");

if($_GET['mode'] == 'update'){

        $bot_api_code = trim($_POST['bot_api_code']);
        $bot_chat_id = trim($_POST['bot_chat_id']);
    
        if(!$bot_chat_id && !$bot_chat_id){
            echo "<script>alert('누락된 정보가 있습니다.'); location.href = '{$PHP_SELF}?mode=select'; </script> ";
            exit();
        }//
    
        sql_query(" update {$g5['telegram_table']} set bot_api_code = '$bot_api_code', bot_chat_id = '$bot_chat_id' ");
        echo "<script>alert('정상적으로 DB에 반영됐습니다.'); location.href = '{$PHP_SELF}?mode=select'; </script> ";
        exit();         
    
}elseif($_GET['mode'] == 'reset'){

    sql_query(" truncate table {$g5['telegram_table']} ");
    sql_query(" insert into {$g5['telegram_table']} VALUES (1, '','') ");
    echo "<script>alert('정상적으로 초기화가 완료됐습니다.'); location.href = '{$PHP_SELF}?mode=select'; </script> ";            
    
} // end
?>
<form action='<?=$PHP_SELF;?>?mode=update' method=post>
    <div class="local_desc02 local_desc" style="background:#f3f4f3;">
        <p>이 서비스는 'SIR.CO.KR' 에서 활동하는 '유진201907' 이 개발한 텔레그램 플러그인의 기본설정을 하는 데 목적이 있습니다. </p>
    </div>
    <div class="tbl_frm01 tbl_wrap">
            <table>
            <caption>홈페이지 기본환경 설정</caption>
            <colgroup>
                <col class="grid_4">
                <col>
                <col class="grid_4">
                <col>
            </colgroup>
            <tbody>
                
            <tr>
                <th scope="row"><label for="cf_title">수신 BOT API CODE<strong class="sound_only">필수</strong></label></th>
                <td colspan="3"><input type="text" name="bot_api_code" value="<?php if($row['bot_api_code']){ echo $row['bot_api_code']; } ?>" placeholder='435070531:AFFCwB4JfvU6hai1u_Osal3dYcERx4F67wQ' id="cf_title" required="" class="required frm_input" size="80"></td>
            </tr>
            <tr>
                <th scope="row"><label for="cf_admin">수신 BOT CHAT ID<strong class="sound_only">필수</strong></label></th>
                <td colspan="3"><input type="text" name="bot_chat_id" value="<?php if($row['bot_chat_id']){ echo $row['bot_chat_id']; } ?>" placeholder="354402611" id="cf_title" required="" class="required frm_input" size="80"></td>
            </tr>
            <tr>
                <th scope='row'>관리하기</th>
                <td colspan=3>
                    <input type="submit" value="DB에 반영 요청하기" class="btn_submit btn" accesskey="s">
                    <input type="button" onclick="location.href = '<?=$PHP_SELF;?>?mode=reset'; " value="DB 리셋" style="background:#3f51b5;" class="btn_submit btn" accesskey="s">
                
                </td>
            </tr>
            </tbody>
            </table>
        </div>
    <div class="local_desc02 local_desc" style="background:#f3f4f3;">
        <p><strong>◆ 텔레그램 봇 생성방법:</strong> <a href='https://hatpub.tistory.com/48' target=_blank>https://hatpub.tistory.com/48</a></p>
        <p><strong>◆ Bot 생성 후 Chat_id 구하기:</strong> <a href='https://blog.acidpop.kr/216' target=_blank>https://blog.acidpop.kr/216</a></p>
        <?php if($row['bot_api_code']){ ?>
        <p><strong>◆ Bot 생성 후 Chat_id 구하기:</strong> <a href="https://api.telegram.org/bot<?php echo $row['bot_api_code']; ?>/getUpdates" target="_blank">https://api.telegram.org/bot<?php echo $row['bot_api_code']; ?>/getUpdates</a>
        <?php } ?>
    </div>
</form>
<?php
include_once(G5_ADMIN_PATH.'/admin.tail.php');
?>


6. extend / telegram.extend.php
<?php
if (!defined('_GNUBOARD_')) exit;

$g5['telegram_table'] = G5_TABLE_PREFIX . "telegram_setting";    // 
?>


7. bbs / memo_form_update.php

    $str_nick_list = implode(',', $member_list['nick']);

아래에 내용을 추가합니다.

    if ($recv_mb_id=="관리자ID") { // 텔레그램으로 PUSH 받고자 하는 회원ID를 입력합니다.
        include_once(G5_ADMIN_PATH.'/telegram/telegram.lib.php');
        $telegram_msg = $_POST['me_memo'];
        curl_tele_sent("[Memo] ".$member['mb_id']." (".$member['mb_nick'].") ".$telegram_msg);
    }


8. bbs / write_comment_update.php



9. bbs / write_update.php
페이지 끝의 goto_url 위의 적당한 곳에 아래 코드를 추가합니다.

if ($w=="" || $w=="w") {
    if ($bo_table=="게시판ID") { // 특정 게시판의 신규 글일때만 작동
        include_once(G5_ADMIN_PATH.'/telegram/telegram.lib.php');
        $telegram_msg  = get_text(strip_tags($wr_content))." ";
        $telegram_msg .= G5_BBS_URL."/board.php?bo_table=".$bo_table;
        //$telegram_msg  = G5_BBS_URL."/board.php?bo_table=".$bo_table."&amp;wr_id=".$wr_id;
        curl_tele_sent("[Board] ".$member['mb_id']." (".$member['mb_nick'].") ".$telegram_msg);
    }
}

댓글목록

등록된 댓글이 없습니다.


Total 460건 2 페이지
  • RSS
기술자료 목록
440
그누보드   5214  2021-10-24 02:39  
439
그누보드   5324  2021-10-08 17:20 ~ 2021-10-21 15:24  
438
그누보드   5579  2021-10-08 14:45 ~ 2021-10-08 16:11  
437
그누보드   6692  2021-10-08 07:41 ~ 2021-10-14 10:40  
436
그누보드   5041  2021-09-02 12:15 ~ 2021-09-02 15:15  
435
그누보드   5001  2021-08-31 18:52  
434
그누보드   5296  2021-08-01 20:59 ~ 2021-08-02 09:19  
433
그누보드   7078  2021-07-27 14:45 ~ 2021-08-05 18:06  
432
그누보드   5913  2021-06-30 07:32 ~ 2021-06-30 07:50  
431
그누보드   7727  2021-06-11 09:19 ~ 2021-06-11 09:20  
430
그누보드   6542  2021-06-03 16:20 ~ 2021-06-06 14:56  
429
그누보드   5861  2021-05-26 11:53 ~ 2021-05-27 08:49  
428
그누보드   8299  2021-05-18 13:48 ~ 2021-07-22 12:24  
427
그누보드   5613  2021-04-21 17:55 ~ 2021-06-15 18:19  
426
그누보드   4869  2021-02-25 22:28 ~ 2021-03-17 11:33  
425
그누보드   6432  2021-02-18 10:28 ~ 2021-02-18 14:10  
424
그누보드   6902  2021-02-08 14:43 ~ 2021-02-08 16:31  
423
그누보드   8073  2020-12-14 18:09 ~ 2023-04-04 11:18  
422
그누보드   6749  2020-12-07 15:15 ~ 2022-12-17 21:15  
421
그누보드   4785  2020-10-19 06:39 ~ 2022-02-01 09:57  

검색

해피정닷컴 정보

회사소개 회사연혁 협력사 오시는길 서비스 이용약관 개인정보 처리방침

회사명: 해피정닷컴   대표: 정창용   전화: 070-7600-3500   팩스: 042-670-8272
주소: (34368) 대전시 대덕구 대화로 160 대전산업용재유통단지 1동 222호
개인정보보호책임자: 정창용   사업자번호: 119-05-36414
통신판매업신고: 제2024-대전대덕-0405호 [사업자등록확인]  
Copyright 2001~2025 해피정닷컴. All Rights Reserved.