Ich war Heute nicht in der Schule und wusste nichts mit mir anzufangen ¯\_(ツ)_/¯ , das Resultat ist inspiriert von dem momentanen Projekt GRP App: Helfer gesucht. (Bin einfach zu gehypt davon *_*)
Sprich eine sozusagen (Erweiterung?) für beliebige E2s um sie mit Telegram (Eine Android Chat App) zu verknüpfen.
Dazu benutzt habe ich die Telegram Api (https://core.telegram.org/bots/api) und die Http Funktionen für E2.
Vlt findet ja zuffälig einer von euch davon gebrauch :o
HTML
- #Version 1.1:
- @name Telegram Modul
- @inputs
- @outputs
- @trigger
- @persist TokenTel:string UrlTel:string ModeTel:string MsgTel:string ChatidTel:string MChatidTel:string OffsetTel ContactsTel:table WhitelistTel:table KeyboardTel:table SoundindicatorTel TickTel USTel TextTel:string
- interval(10)
- runOnHTTP(1)
- runOnLast(1)
- runOnChat(1)
- #Telegram Modul
- ############################################################
- #Settings
- if(first()) {
- TokenTel="" #The Token from you Telegram Bot.
- UrlTel="https://api.telegram.org/bot"+TokenTel
- MChatidTel="" #Your main Chat Id
- #WhitelistTel["",number]=1 #Whitelist for the commands. If no one is in the whitelist its deactivated. Whitelist["<Chat Id>,number"]=1
- ModeTel="check"
- #SoundindicatorTel=1 #If active its indicates commands with a button sound.
- #Pre installed Telegram commands
- #"/start" To get your Chat Id
- #"/chatid" To get your Chat Id
- #"/ping" Pong!
- #"/420"
- }
- #/Settings/
- #Description
- #Setup
- #1.Go to Telegram
- #2.Click on BotFather
- #3.Type in /newbot
- #4.Find an avaible name for your bot. Hint: Keep it secret, this E2 doesnt have an Spam protection.
- #5.Grab the API Key and paste it in the Token Variable above.
- #6.Send your Bot a "/start"
- #Optional if you want to listen every Messages not just the ones who start with /
- #7.Type in /setprivacy
- #8.Select your Bot.
- #9.Type in Disable
- #E2 Functions
- #Send an message: sendmsg(Chatid:string,Message:string)
- #Send an message with a costum Keyboard layout:
- #Before you send an message via. sendmsg() you need to change the follow Table
- #Example: KeyboardTel["keyboard",table]=table(table("1","2","3"),table("4","5","6"),table("7","8","9")) #This displays a 3x3 Field.
- #TickTel is true for one tick long if a message was recieved
- #The ContactsTel Table saves all Chatids under the first names Example: sendmsg(ContactsTel["Moritz",string],"Its just a test!")
- #/Description
- ############################################################
- #Automate Update
- if(!USTel&httpCanRequest()) {
- print("Begin with searching for updates.")
- print("----------------")
- USTel=1
- httpRequest("http://pastebin.com/raw/yw8i4F1b")
- }
- if(httpClk()&USTel==3) {
- DatasTel=httpData()
- print("Update!")
- print("-----------")
- #print("Version "+Datas[2,string])
- print("Changes:")
- print(DatasTel)
- print("The e2 is saved in you e2shared folder!")
- print("-----------")
- USTel=420
- }
- if(httpClk()&USTel==1) {
- Data=httpData():explode(":")[1,string]:explode(" ")
- if(Data[2,string]:toNumber()>1.1) {
- hint("Update was found!",4)
- fileWrite(">e2shared/Telegram Modul.txt",httpData())
- USTel=2
- } else {
- USTel=420
- print("No updates was found.")
- }
- }
- if(USTel==2&httpCanRequest()) {httpRequest("http://pastebin.com/raw/GXvvMB1n") USTel=3}
- TickTel=0
- function sendmsg(IdTel:string,MessTel:string) {
- ModeTel="send"
- MsgTel=httpUrlEncode(MessTel)
- ChatidTel=IdTel
- #print("send "+httpUrlDecode(Msg)+" to "+Id)
- }
- #/Automate Update/
- #[if(last()) {
- if(MChatid:length()>2) {
- httpRequest(Url+"/sendmessage?chat_id="+MChatid+"&text="+entity():getName()+" is shutingdown now.")
- }
- print(httpRequestUrl())
- }]#
- if(httpCanRequest()&USTel==420) {
- if(ModeTel=="recieve") {
- httpRequest(UrlTel+"/getUpdates?offset="+OffsetTel)
- ModeTel="recieve"
- #print(httpRequestUrl())
- }
- if(ModeTel=="send") {
- if(KeyboardTel["keyboard",table]:count()) {
- KYTel=KeyboardTel["one_time_keyboard",normal]=666
- ArgTel=jsonEncode(KeyboardTel):replace("666","true"):replace(toChar(34),"%22")
- KFTel="&reply_markup="+ArgTel
- # print(KF)
- }
- httpRequest(UrlTel+"/sendmessage?chat_id="+ChatidTel+"&text="+MsgTel+KFTel)
- KFTel=""
- KeyboardTel["keyboard",table]=table()
- #print(httpRequestUrl())
- ModeTel="recieve"
- }
- if(ModeTel=="check") {
- httpRequest(UrlTel+"/getme")
- }
- }
- if(httpClk()&httpRequestUrl():find(UrlTel)) {
- if(ModeTel=="check") {
- DataTel=httpData()
- TeTel=jsonDecode(DataTel)
- if(TeTel["ok",number]) {
- hint("Your now connected with "+TeTel["result",table]["username",string],4)
- ModeTel="recieve"
- if(MChatidTel:length()>2) {
- sendmsg(MChatidTel,"Your E2 "+toChar(34)+entity():getName()+toChar(34)+" is running now.")
- }
- } else {
- ModeTel="error"
- hint("Your Bot Token seem to be wrong, pls retry.",4)
- }
- }
- if(ModeTel=="recieve") {
- DataTel=httpData()
- TeTel=jsonDecode(DataTel)
- MTTel=TeTel["result",table]
- NachrichtenCTel=MTTel:count() #Anzahl der Nachrichten
- if(MTTel[1,table]["update_id",number]) {
- OffsetTel=MTTel[1,table]["update_id",number]+1 #Loeschen der ersten Nachricht
- }
- #print(NachrichtenC)
- #print(MT:toString())
- if(NachrichtenCTel) {
- TickTel=1
- if(SoundindicatorTel) {
- owner():soundPlay(1,1,"buttons/button14.wav")
- }
- }
- for(X=1,NachrichtenCTel) {
- DetailsTel=MTTel[X,table]["message",table]
- TextTel=DetailsTel["text",string]:lower()
- AbsenderTel=DetailsTel["chat",table]["first_name",string]:lower()
- ChatidTel=DetailsTel["chat",table]["id",number]:toString()
- ContactsTel[AbsenderTel,string]=ChatidTel
- #print(Text)
- if((WhitelistTel:count()&WhitelistTel[ChatidTel,number])|!WhitelistTel:count()) {
- ##############################################################
- #Commands
- if(TextTel:find("/ping")) {
- sendmsg(ChatidTel,"pong!")
- hint("pong!",2000)
- #print("pong!")
- }
- if(TextTel:find("/chatid")|TextTel:find("/start")) {
- sendmsg(ChatidTel,"Hey buddy! Your Chatid is "+ChatidTel)
- }
- if(TextTel:find("/420")) {
- KeyboardTel["keyboard",table]=table(table("4","2","0"),table("4","2","0"),table("4","2","0"))
- sendmsg(ChatidTel," blaze it.")
- }
- #/Commands/
- ##############################################################
- }
- }
- }
- }
- #/Telegram Modul/