Well that blows, I'm going to try using POST then, I'll 'post' it here when i figure it out.
And It seems i don't really use my browser nearly as well as i should, cheers.
Well that blows, I'm going to try using POST then, I'll 'post' it here when i figure it out.
Hi - this is exactly what I needed for my windows PC that I want to control. Now I have to work out how to post to tlk.io from MacroDroid or Tasker (or similar) as I am trying to automate action according to my phone location... Macrodroid can post HTTP request and has json parser but I have no idea what I need to put in them... any help will be appreciatedTheDewd wrote: ↑21 May 2019, 13:55You should use the JSON data from the API. I discovered the API data by monitoring the data transfer as I interacted with the website.
Here's a script I wrote to get the latest message text from a channel.
All of the returned JSON attributes are included in the script.Code: Select all
#SingleInstance, Force #Persistent ;// The name assigned to the channel ChannelName := "hey" ;// Get the unique chat_id value using the channel name HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1") HttpRequest.Open("GET", "https://tlk.io/" ChannelName, true) HttpRequest.Send() HttpRequest.WaitForResponse() RegExMatch(HttpRequest.ResponseText, "chat_id\s=\s'(\d+)';", ChatID) ;// Get the JSON data returned from the API URL HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1") HttpRequest.Open("GET", "https://tlk.io/api/chats/" ChatID1 "/messages", true) HttpRequest.Send() HttpRequest.WaitForResponse() ;// Parse the JSON data ChatLog := [{}] ;// Create an array containing an object Pos := 1, Match := "" While (Pos := RegExMatch(HttpRequest.ResponseText, "({.*?})", Match, Pos + StrLen(Match))) { RegExMatch(Match1, """id"":(\d+),", id) RegExMatch(Match1, """user_token"":""(.*?)"",", user_token) RegExMatch(Match1, """nickname"":""(.*?)"",", nickname) RegExMatch(Match1, """body"":""(.*?)"",", body) RegExMatch(Match1, """user"":{(.*?)},", user) RegExMatch(user1, """token"":""(.*?)"",", u_token) RegExMatch(user1, """nickname"":""(.*?)"",", u_nickname) RegExMatch(user1, """provider"":""(.*?)"",", u_provider) RegExMatch(user1, """avatar"":""(.*?)"",", u_avatar) RegExMatch(user1, """profile_url"":""(.*?)""}", u_profile_url) RegExMatch(Match1, """timestamp"":(\d+),", timestamp) RegExMatch(Match1, """closest_milestone"":(\d+),", closest_milestone) RegExMatch(Match1, """deleted"":(.*?)}", deleted) ;// Assign parsed items to the array ChatLog[A_Index] := {"id": id1 ,"user_token": user_token1 ,"nickname": nickname1 ,"body": body1 ,"u_token": u_token1 ,"u_nickname": u_nickname1 ,"u_provider": u_provider1 ,"u_avatar": u_avatar1 ,"u_profile_url": u_profile_url1 ,"timestamp": timestamp1 ,"closest_milestone": closest_milestone1 ,"deleted": deleted1} } MsgBox, % ChatLog[ChatLog.MaxIndex()].body
Note: Only the last 50 messages are available to view. If you don't see any results, see if your channel's messages have been deleted...
Login using Facebook/Twitter, and then become the moderator of the channel, and the messages aren't automatically deleted (as far as I can tell...)
You can setup the script to wait for commands like this:Code: Select all
#SingleInstance, Force #Persistent MyChatID := GetChatID("YourChannelName") ;// The name assigned to the channel SetTimer, ParseChatLog, 3000 ;// 3 seconds return GetChatID(Channel) { ;// Get the unique chat_id value using the channel name HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1") HttpRequest.Open("GET", "https://tlk.io/" Channel, true) HttpRequest.Send() HttpRequest.WaitForResponse() RegExMatch(HttpRequest.ResponseText, "chat_id\s=\s'(\d+)';", ChatID) return ChatID1 } GetChatLog(ChatID) { ;// Get the JSON data returned from the API URL HttpRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1") HttpRequest.Open("GET", "https://tlk.io/api/chats/" ChatID "/messages", true) HttpRequest.Send() HttpRequest.WaitForResponse() return HttpRequest.ResponseText } ParseChatLog() { ;// Parse the JSON data Global MyChatID Static LastID MyChatLog := GetChatLog(MyChatID) ;// Get the JSON data ChatLog := [{}] ;// Create an array containing an object Pos := 1, Match := "" While (Pos := RegExMatch(MyChatLog, "({.*?})", Match, Pos + StrLen(Match))) { RegExMatch(Match1, """id"":(\d+),", id) RegExMatch(Match1, """user_token"":""(.*?)"",", user_token) RegExMatch(Match1, """nickname"":""(.*?)"",", nickname) RegExMatch(Match1, """body"":""(.*?)"",", body) RegExMatch(Match1, """user"":{(.*?)},", user) RegExMatch(user1, """token"":""(.*?)"",", u_token) RegExMatch(user1, """nickname"":""(.*?)"",", u_nickname) RegExMatch(user1, """provider"":""(.*?)"",", u_provider) RegExMatch(user1, """avatar"":""(.*?)"",", u_avatar) RegExMatch(user1, """profile_url"":""(.*?)""}", u_profile_url) RegExMatch(Match1, """timestamp"":(\d+),", timestamp) RegExMatch(Match1, """closest_milestone"":(\d+),", closest_milestone) RegExMatch(Match1, """deleted"":(.*?)}", deleted) ;// Assign parsed items to the array ChatLog[A_Index] := {"id": id1 ,"user_token": user_token1 ,"nickname": nickname1 ,"body": body1 ,"u_token": u_token1 ,"u_nickname": u_nickname1 ,"u_provider": u_provider1 ,"u_avatar": u_avatar1 ,"u_profile_url": u_profile_url1 ,"timestamp": timestamp1 ,"closest_milestone": closest_milestone1 ,"deleted": deleted1} } ;// Do nothing if no new messages If (LastID = ChatLog[ChatLog.MaxIndex()].id) { return } ;// Store ID of last message to variable LastID := ChatLog[ChatLog.MaxIndex()].id ;// Execute command based on the message text ExecuteCommand(ChatLog[ChatLog.MaxIndex()].body) } ExecuteCommand(Text) { If (Text = "MsgBox") { ;// Keyword 1 MsgBox, % Hello World! ;// Display message box } Else If (Text = "Start") { ;// Keyword 2 Send, {LWin} ;// Open start menu } Else If (Text = "Notepad") { ;// Keyword 3 Run, notepad.exe ;// Run notepad } Else { ;// Other If (Text = "") { return ;// Do nothing if no text (messages deleted, etc...) } MsgBox, % Text ;// Show text if not matching defined keywords } }
Code: Select all
#SingleInstance, Force
HttpReq := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HttpReq.Open("POST", "https://tlk.io/api/participant")
HttpReq.SetRequestHeader("Content-Type", "application/json")
HttpReq.Send("{""nickname"":""AutoHotkey1234""}")
HttpReq.WaitForResponse()
MsgBox, % HttpReq.ResponseText
MsgBox, % HttpReq.getAllResponseHeaders()
HttpReq := ComObjCreate("WinHttp.WinHttpRequest.5.1")
HttpReq.Open("POST", "https://tlk.io/api/chats/9275239/messages") ; https://tlk.io/mysupersecretchannelname
HttpReq.SetRequestHeader("Content-Type", "application/json")
HttpReq.Send("{""body"":""AutoHotkey Test"",""expired"":false}")
HttpReq.WaitForResponse()
MsgBox, % HttpReq.ResponseText
MsgBox, % HttpReq.getAllResponseHeaders()
I have tried to implement it into the autohotkey script but did not work... posting iy just in case it makes more sense to you than me...me - write an HTTP request to post message on tlk.io
chatGPT - Sure! Here's an example of an HTTP request to post a message on tlk.io:
makefile
Copy code
POST https://tlk.io/room_name/messages.json HTTP/1.1
Host: tlk.io
Content-Type: application/json
Content-Length: [length of JSON payload]
{
"body": "Hello, this is my message!",
"nickname": "my_nickname",
"user_id": "my_user_id"
}
In this example, you would need to replace "room_name" with the actual name of the tlk.io room you want to post the message in. The JSON payload contains the message body, your chosen nickname, and your user ID. Make sure to replace "Hello, this is my message!" with the actual message you want to post, and "my_nickname" and "my_user_id" with your chosen nickname and user ID.
Note that you would also need to authenticate the request by including a valid API key or access token in the request headers, depending on the authentication method used by tlk.io.
me - write http request that creates a new user on tlk.io in room called london
chatGPT - Unfortunately, tlk.io doesn't offer an API to create new users. Users are created automatically when they join a room for the first time using a unique nickname.
However, if you want to join a room called "london" on tlk.io using a specific nickname, you can send a GET request to the following URL:
arduino
Copy code
https://tlk.io/london?nick=your_nickname
Replace "your_nickname" with the nickname you want to use. This will join the "london" room with the specified nickname. If the nickname is already taken, tlk.io will generate a new one for you.
Note that tlk.io doesn't offer an official API, so this method may not be supported or guaranteed to work in the future.
Return to “Scripts and Functions (v1)”
Users browsing this forum: LAPIII and 82 guests