REVO7000Telegram ChatBot @vnD?   cREVGeneral breakpointstates)active active active active active active breakpoints71002,1088 1002,1095 1002,717 1002,856 1002,739 1002,227breakpointconditions scalefactor? Pglobal gURL global GSTOP local sNamedAddress on openstack constant MYTOKEN = "" put "https://api.telegram.org/bot" & MYTOKEN & "/" into gURL main end openstack function get_json_from_url purl put URL pURL into temp put JSONToArray(temp) into tRes return tRes end get_json_from_url function getUpdates pOffset put gURL & "getUpdates" into tURL if pOffset is not empty then put "?offset=" & pOffset after tURL end if put get_json_from_url(tURL) into tAjson return tAjson end getUpdates function get_last_update_id updates repeat for each element EE in updates["result"] put EE["update_id"] & COMMA after temp end repeat put max(temp) into tt1 return max(temp) end get_last_update_id function buildKeyboard pText set the itemDel to TAB repeat for each line L in pText add 1 to i put 0 into j repeat for each item T in L add 1 to j put T into tA[i][j] end repeat end repeat put tA into tempA["keyboard"] put true into tempA["one_time_keyboard"] put arraytoJSON(tempA) into tJ return tJ end buildKeyboard function buildLocationKeyboard -- show only a "send location" an a "cancel" button put "Set Location" into tA[1][1]["text"] put TRUE into tA[1][1]["request_location"] put "Cancel" into tA[2][1]["text"] put tA into tempA["keyboard"] put true into tempA["one_time_keyboard"] put arraytoJSON(tempA) into tJ return tJ end buildLocationKeyboard global gCode, gLatLong, gAddresses, gShortAddresses command doAPostcode pCode set the itemDel to TAB put pCode into gCode replace space with "-" in gCode put URL ("https://kilmelford.com/igniter.lc/addresses/getfile/" & gCode) into t if item 1 of line 1 of t = gCode then put item 2 of line 1 of t into gLatLong put line 2 to -1 of t into gAddresses else -- No need to retrieve from public database - all postcode fiels are now cached as needed on -- my server at kilmelford.com ask "There is a problem with the postcode file for" && gCode exit doAPostCode end if buildShortAddresses end doAPostcode command buildShortAddresses set the itemDel to TAB put empty into gShortAddresses repeat for each line L in gAddresses if item 3 of L = "default" then replace "&" with "&" in item 2 of L replace "'" with "'" in item 2 of L if NOT (item 2 of L contains "&") then put item 2 of L & CR after gShortAddresses end if end if if the number of lines in gShortAddresses > 4444 then exit repeat end repeat end buildShortAddresses command setAddress pAddress, pLat, pLong set the itemDel to TAB repeat with i = 1 to the number of lines in gAddresses put line i of gAddresses into L if item 2 of L = pAddress then put "set" into item 3 of line i of gAddresses put pLat & "/" & pLong into item 4 of line i of gAddresses exit repeat end if end repeat put "https://kilmelford.com/igniter.lc/addresses/storeAddress/" & gCode \ & "/" & URLEncode(line i of gAddresses) into tURL put URL (tURL) into t end setAddress local sActiveAddress function handleUpdates updates repeat for each element EE in updates["result"] put EE["message"]["text"] into tText put EE["message"]["chat"]["id"] into tChat switch case tText is empty and EE["message"]["location"]["latitude"] is not empty setAddress sActiveAddress, EE["message"]["location"]["latitude"], EE["message"]["location"]["longitude"] buildShortAddresses put empty into sActiveAddress put buildKeyboard(gShortAddresses) into tKB put sendMessage("Choose an address in" && gCode, tChat, tKB) into temp break case tText begins with "/start" put sendMessage("Welcome to the UK House & Property Locator. " & CR & \ "Send me a Postcode, e.g." & CR & \ " /location,PA34 4XD" & CR & \ "Then choose a property when you are standing outside it, and then click to set" & \ " the GPS location to be stored for that property.", tChat) into temp break case tText begins with "/save" put sendMessage("Saving is currently not allowed.", tChat) into temp break case tText begins with "/keyboard" put buildKeyboard("a,b,c" & CR & "d,e") into tKB put sendMessage("here's a keyboard", tChat, tKB) into temp break case tText begins with "/location" put item 2 of tText into t2 if t2 is empty then put "PA34 4XD" into t2 doAPostCode t2 -- NB fall through here !! case tText = "Cancel" put buildKeyboard(gShortAddresses) into tKB put sendMessage("Choose an address in" && gCode, tChat, tKB) into temp break case tText begins with "/" break default if tText is among the lines of gShortAddresses then put tText into sActiveAddress put buildLocationKeyboard() into tKB put sendMessage("And send its location (or cancel)", tChat, tKB) into temp else put sendMessage("echo" & tText, tChat) into temp end if end switch end repeat return temp end handleUpdates function sendMessage pText, pChatID, pReplyMarkUp put URLEncode(pText) into tt put gURL & "sendMessage" into tURL put "text=" & tt & "&chat_id=" & pChatID & "&parse_mode=Markdown" into tPost if pReplyMarkUp is not empty then put "&reply_markup=" & pReplyMarkUp after tPost end if post tPost to URL tURL -- ask it & "::" && the result end sendMessage command main put FALSE into gSTOP put empty into lastUpdateID repeat forever if GSTOP then exit repeat put getUpdates(lastUpdateID) into updates if updates["result"] is not empty then put get_last_update_id(updates) + 1 into lastUpdateID put handleUpdates(updates) into temp end if wait 1 second with messages end repeat end main -- function to determine if a string can be decomposed with two separators, -- and if so, to return the 3 parts (before, middle, and after) around those separators function decompose2 pIn, pSep1, pSep2, @p1, @p2, @p3 put offset(pSep1, pIn) into t1 if t1 > 0 then put char t1+the number of chars in pSep1 to -1 of pIn into tIn put offset(pSep2, tIn) into t2 if t2 > 0 then put char 1 to t1-1 of pIn into p1 put char 1 to t2-1 of tIn into p2 put char t2+the number of chars in pSep2 to -1 of tIn into p3 return TRUE end if end if return FALSE end decompose2 D:  cREVGeneral scripteditorvscrollscripteditorselection187STOPEp revOnline | RunRev