1.) สร้างแบบฟอร์ม สำหรับกรอกข้อมูล เพื่อส่งข้อความจากหน้าเว็บไปยัง Telegram-Notify API ตั้งชื่อไฟล์เป็น telegram-notify.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Contact Us via Telegram-Notify</title>
<meta name="language" content="TH" >
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<center>
<form name="Telegram-Notify" action="Telegram-Notify-api.php" method="post">
<table width="450" border="0" cellspacing="0" cellpadding="0">
<tr><td colspan="2" align="center"><img src="images/telegram-logo.jpg" border="0"></td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td colspan="2" align="center"><font color="#0000ff"><b>กรุณากรอกรายละเอียด</b></font></td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td>ชื่อ:</td><td><input class="textInput" type="text" name="name" size="25" required> *</td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td>อีเมล์:</td><td><input class="textInput" type="text" name="email" size="25" required> *</td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td>โทรศัพท์:</td><td><input class="textInput" type="text" name="phone" size="25" required> (Option)</td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td>Telegram ID:</td><td><input class="textInput" type="text" name="lineid" size="25" required> (Option)</td></tr>
<tr><td colspan="2" height="10"></td></tr>
<tr><td>ข้อความ:</td><td><textarea rows='5' name='mesg' cols='50' style='border: 1 solid #99FF00'>ความยาวไม่เกิน 600 ตัวอักษร</textarea>
<tr><td colspan="2" height="10"></td></tr>
<tr><td colspan=2 align="center"><input type="submit" name="submit" value=" ส่งข้อความ "></td></tr>
<tr><td colspan="2" height="10"></td></tr>
</table>
</form>
</center>
</body>
</html>
ตัวอย่างการแสดงผลหน้า telegram-notify.html

2.) สร้าง script php เพื่อรับค่า input จาก telegram-notify.html เพื่อส่งข้อมูลไป Telegram API Server โดยตั้งชื่อไฟล์เป็น telegram-notify-api.php
<?php
foreach ($_POST as $key => $value) {
//echo "Field ".htmlspecialchars($key)." is ".htmlspecialchars($value)."<br>";
$mesg.= "Field ".htmlspecialchars($key)." = ".htmlspecialchars($value)."\n";
}
$message=urlencode($mesg);
if($message !="") {
sendtelegrammesg();
header('Content-Type: text/html; charset=utf-8');
$res = notify_message($message);
echo "<center>ส่งข้อความเรียบร้อยแล้ว</center>";
} else {
echo "<center>Error: กรุณากรอกข้อมูลให้ครบถ้วน</center>";
}
function sendtelegrammesg() {
function notify_message($message){
$TOKEN_KEY = "Your_Token_Key";
$CHATID = "Your_Chat_ID";
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,"https://api.telegram.org/bot$TOKEN_KEY/sendMessage?chat_id=$CHATID&text=$message");
// Execute
$result = curl_exec($ch);
// Closing
curl_close($ch);
// แปลงข้อมูลที่รับมาในรูป json มาเป็น array จะได้ใช้ง่าย ๆ
//$DATA = json_decode($result, true);
$res = json_decode($result);
//dump ข้อมูลออกมาดู
//print_r($res);
return $res;
}
}
?>
3.) การออก TOKEN เพื่อใช้งาน Telegram API เปิดโปรแกรม Telegram บน PC Desktop

4.) ค้นหาคำว่า botfather" และกด START

5.) สร้างบอท ด้วยการพิมพ์ /newbot แล้วกด Enter

6.) พิมพ์ชื่อ bot ตามต้องการ เช่น mybotmsg แล้วกด Enter

7.) พิมพ์ชื่อ bot อีกครั้งโดยใส่ _bot ต่อท้ายชื่อ เช่น mybotmsg_bot แล้วกด Enter
ท่านจะได้ Token Key ให้ Copy เก็บไว้ และเอาไปใส่ในไฟล์ telegram-notify-api.php ตรง $TOKEN_KEY = "Your_Token_Key";

8.) คลิกที่ลิงค์ ตามที่เห็นในภาพ หรือ พิมพ์ชื่อ bot ของท่านในช่องค้นหา

9.) กดปุ่ม START หรือพิมพ์ /start เพื่อเริ่มใช้งาน bot ของท่าน

10.) การหาหมายเลข CHAT ID ของท่าน โดยเข้าไปที่
https://api.telegram.org/bot
$TOKENID/getUpdates <-- เปลี่ยน $TOKENID เป็น Token Key ของท่าน
ตัวอย่าง: https://api.telegram.org/bot
589577626:AAFX6ycOyrLzyrzeVYIp_YvYXNbqh0QVY3o/getUpdates

11.) ให้ Copy ID เก็บไว้ และเอาไปใส่ในไฟล์ telegram-notify-api.php ตรง $CHATID = "Your_Chat_ID"; ตัวอย่าง $CHATID = "557508161";
12.) ทำการทดสอบ โดยการเปิดไฟล์ telegram-notify.html กรอกรายละเอียด และ คลิกปุ่ม ส่งข้อความ
ท่านจะได้รับข้อความแจ้งเตือนใน Telegram ดังนี้

คลิกเพื่อ Download ไฟล์ตัวอย่าง (เพียงแก้ไข TOKEN_KEY และ CHATID ก็สามารถใช้งานได้เลย) -->
telegram-notify-contact-us.rar (Update: 25/04/2018)
หรือ Save เก็บไว้ใน Google Drive ของคุณ
แตกไฟล์ออก แล้ว Upload ขึ้นไปไว้บน Server