Try   HackMD

如何使用TG_TO_LINE BOT

小企鵝



這邊預設是甚麼都不懂如我,如果會的直接點連結就好,也很清楚。
版本是v3版,之後不一定相容。(已過時,之後再修改)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

採 姓名標示-非商業性-相同方式分享 3.0 台灣 (CC BY-NC-SA 3.0 TW)

首先,鼻用下載任何東西,全部雲端跑就好啦。
https://github.com/we684123/Telegram_link_Line

記得先點星星

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

然後開始進入準備材料的部分。

名筆Sat, Sep 8, 2018 07:23 PM
先了解整體概念:

你←→TG端(由TGbot負責)←→雲端(資料轉送,需要有兩端token)←→Line端(由Linebot負責)
token可以想像成key或是id的概念,有token就能夠抓到特定bot
因此步驟就會是:

1.建立telegram 機器人
2.建立Line 機器人(以後就是你的替身)
3.建立雲端中轉站,貼上程式碼、將兩端token填入
4.測試
5.了解兩端bot使用方式、然後將line_bot加入line群組
6.大功告成

開工啦!

1.建立telegram 機器人

在Telegram 中召喚機器人老爸 @BotFather

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

接著進去點 /start

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

輸入想要的名字(中英文皆可,隨便打

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

這邊要打UserName 全英文大小寫皆可(line to tg 之類的。記得結尾要bot並且空格全部都用_代替。
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

反正看得懂就好。(UserName有唯一性所以先打先贏喔

這時會出現這個

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

使用指令 /mybots

第一次用選項下面只會出現一個,反正就是剛剛取的UserName

戳他

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

除了 Commands 之外,其他按選項填寫~

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

main - 開啟主選單
allread - 全部已讀
debug - 重生資料(bot壞掉時用)(不會讓房間不見)
exit - 離開對話

複製上面那串指令丟進去~
然後TG bot就暫時結束~

2.建立 Line 機器人

先戳這個網址
https://developers.line.me/en/

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

下面那張圖點進去會問名字跟信箱,隨便打,收的到信就好。(這個是之後叫出來的,原本建的時候沒截圖

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

點點點

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

就點點點

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

戳 start

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

這邊就是取個專案名稱(可能長得不一樣
ex. 我要長高十公分之類的

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

一系列的相關訊息輸入(這邊要注意 APP Name 就是bot的名字,取個好聽點的

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

要開發者計畫喔,不然功能不全

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

這邊隨便選,反正就是個資蒐集

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

※要注意:此處非輸入G-mail 等網址,我卡在這邊一陣子。是要按照他的範本,取個ddddd@line.me 這樣(ddddd那邊改掉(鼻要複製這邊喔

接著是各種資料蒐集要求同意~

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

如果沒問題,bot 就生好啦。

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

戳進去

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

這邊有等一下要用的資料




ps. line bot的登入方式目前是用 qr code(一般的qr code程式就可以開了 位置一樣是在 chaanel settings 往下拉到底

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

3.開始進入關鍵嘍

登入個google 帳號(建議不常用的,避免擔心~

在google 的雲端空間中,建立個資料夾

資料夾裡面

新增一個doc(即google 文件 命名為 doc.gs
新增一個doc(即google 文件 命名為 doc.gs
新增一個sheet(即google 試算表 命名為 line bot
新增一個資料夾,裡邊不放置任何東西。(這個資料夾權限開成知道連結均可檢視

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

點右鍵或新增

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

搜尋 Google Apps Script

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

連結(圖是已經連結好了

再新增個 Google Apps Script 命名為 line bot

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

現在的資料夾裡邊應該長這樣

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

(1. doc. gs 內容

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

把這串文字複製到

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

裡面

(2. line bot sheet 使用

新增五個分頁(page

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

在line 訊息區的 A1 新增 [0,0]

crtl+a or 全選 點格式 選純文字

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

(3. gs 設定

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

把程式碼.gs 的內文清除,複製貼上 Telegram_link_Line.gs

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

再新增指令碼專案

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

命名 baseANDtest.gs

複製貼上

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

接著就到了最後的混合了。

sheet_key、doc_key、FolderId 都是複製從d/ 到 /edit中間那串像亂碼的數字

Telegram_bot_key 可以在Telegram搜尋 @you_id_bot 是一串數字

Telegram_token 是在大數字1 說很重要那邊(在botfather 輸入 /mybots 選擇自己的bot 之後點 API TOKEN




Line_id 跟下面的 CHANNEL_ACCESS_TOKEN 都是在大數字2那邊剛剛要保留的網頁, channel settings 那邊。(CHANNEL_ACCESS_TOKEN 最晚用

最底下

到現在,沒有填寫的剩下 gsURL 跟 Line 的 Token

先點

建立或更新完後,把剛剛複製,結尾是 exec 那串網址貼到 Line的 Webhook URL

貼上後,等一下,再點

成功之後複製 line 的Token (超長的 點issue 點時間後才看的到

把line 的Token 跟 gsURL 貼上剛剛沒貼完的 baseANDtest. gs ,再發佈、部屬一次(記得要把專案版本改成新增

此時接近完工惹~


複製下面這串網址

https://api.telegram.org/bot這邊改掉甲/setWebhook?url=這邊改掉乙&max_connections=1

這邊改掉甲改成 Telegram 的 Token

這邊改掉乙改成 gs發布後的網址(就是部屬完給的那個,跟瀏覽器顯示的不一樣

改完之後在瀏覽器貼上,如果顯示 "Webhook was set" 或 "Webhook already set"就代表大概好了。

在機器人裡面打字基本上延遲一點點時間,如果等一陣子沒有基本上就出了問題。再四處看看有沒有多複製到、沒做到等等的事情。


  • 把機器人加入群組後都要先發一則訊息喔。

  • 如果成功的話,會有一個請重新命名的message 就用 /main 點選你的名字,點重新命名對應到line的名稱就好。

  • 在bot 有個功能叫升級房間。就是再建立一個 Telegram 的 bot ,只要有token 就好(第二步。升級完之後,那個bot 變成專屬 line 的聊天室



打了六個小時,手暴淦痛。如果覺得有用的話可以多多使用 Telegram ,或是來 https://t.me/penguinF 發個心得之類的。(窩也可以聊耳機、書、音樂,歡迎找我玩~

如果有任何錯誤麻煩告知我,有任何疑問拜託鼻要找我(癱

參考資料:

https://github.com/we684123/Telegram_link_Line 的 read me。他拍的tg bot 教學值得一看,比較清楚

https://www.oxxostudio.tw/articles/201701/line-bot.html

https://t.me/AntiLINE 裏頭各個大大還有開發者的幫助