Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Groupme API
#1
Has anyone tried to implement the Groupme API to receive data posted in a group chat?  https://dev.groupme.com/tutorials/push

I was able to create the code needed to post a message into a group chat, but I'd like to also be able to have no posts pushed to me. 

the code I found in the forum post a message was simple and worked perfectly (thanks)
---------------------------
Http Host.Connect("api.groupme.com" 0 0 443)
Host.PostAdd("bot_id" "xxxxxxxxxxxxxxxxxxxxxxxx")
Host.PostAdd("text" F"{text}")
str r8
if(!Host.PostFormData("/v3/bots/post" 0 r8 "" 0 0 INTERNET_FLAG_SECURE)) end "failed"
-----------------------------

But I can't understand how to make the push work. 

Step 1 of the instructions is simply to send a post with this data to https://push.groupme.com/faye

[
 {
   "channel":"/meta/handshake",
   "version":"1.0",
   "supportedConnectionTypes":["long-polling"],
   "id":"1"
 }
]


The code I tried was this:

str r8
str r9
str d1
d1="[''long-polling'']"   ;;inside [] are two single quotes

Http Host.Connect("push.groupme.com" 0 0 443)
str headers
lpstr sh="Content-Type: application/json"
if(empty(headers)) headers=sh

Host.PostAdd("channel" "/meta/handshake") 
Host.PostAdd("version" "1.0")
Host.PostAdd("supportedConnectionTypes" F"{d1}")
Host.PostAdd("id" "1")

if(!Host.PostFormData("faye" 0 r8 headers 0 0 INTERNET_FLAG_SECURE r9)) end "failed"
out r8
out r9

The response was this:

HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Date: Tue, 05 Jun 2018 02:10:45 GMT
Connection: keep-alive
Transfer-Encoding: chunked

Any help to correctly create this POST would really appreciated. I can probably figure out the remaining steps but not 100% about that  Confused
#2
I was able to get the groupme push working. I was not able to use the Host.PostAdd commands instead I had to use this:

typelib WinHttp {662901FC-6951-4854-9EB2-D9A2570F2B2E} 5.1
WinHttp.WinHttpRequest r._create
r.Open("POST" "https://push.groupme.com/faye")
r.SetRequestHeader("Content-Type" "application/json")

str data=
F
{{
"channel":"/meta/handshake",
"version":"1.0",
"supportedConnectionTypes":["long-polling"],
"id":"1"
}

r.Send(data)

Not sure why this works but the Host.PostAdd commands did not.
#3
PostFormData can post only HTML form variables but cannot post body data.
#4
Yes, it's a shame but the workaround was easy once I understood the syntax. Thanks for the update.
#5
PostFormData can post only HTML form variables but cannot post body data.

This should work, but I did not test.
Macro Macro10
Code:
Copy      Help
str data=
F
;{{
;"channel":"/meta/handshake",
;"version":"1.0",
;"supportedConnectionTypes":["long-polling"],
;"id":"1"
;}

str r8
str r9

Http Host.Connect("api.groupme.com" 0 0 443)

Host.Post("faye" data r8 "Content-Type: application/json" INTERNET_FLAG_SECURE r9)
out r8
out r9

With WinHttp.WinHttpRequest also OK.


Forum Jump:


Users browsing this thread: 4 Guest(s)