Created
January 10, 2018 15:28
-
-
Save widarlein/49679264d8b2e1721d3cecb13cb7bfb9 to your computer and use it in GitHub Desktop.
Pushbullet API Send SMS in groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab("com.squareup.okhttp3:okhttp:3.9.0") | |
import okhttp3.MediaType | |
import okhttp3.OkHttpClient | |
import okhttp3.Request | |
import okhttp3.RequestBody | |
import okhttp3.Response | |
import groovy.json.JsonOutput | |
String PUSHBULLET_ACCESS_TOKEN = "ACCESSTOKEN" | |
MediaType JSON = MediaType.parse("application/json; charset=utf-8"); | |
OkHttpClient client = new OkHttpClient() | |
// Find user iden by curling me: curl --header 'Access-Token: <your_access_token_here>' https://api.pushbullet.com/v2/users/me | |
String USER_IDEN = "<user-iden>" | |
// Find device iden by listing your devices: curl --header 'Access-Token: <your_access_token_here>' https://api.pushbullet.com/v2/devices | |
String DEVICE_IDEN = "<device-iden>" | |
String phoneNumber = "00000" | |
String message = "This is the message" | |
def body = [ | |
push: [ | |
message: message, | |
"conversation_iden": phoneNumber, | |
"target_device_iden": DEVICE_IDEN, | |
"source_user_iden": USER_IDEN, | |
"package_name": "com.pushbullet.android", | |
type: "messaging_extension_reply" | |
], | |
type: "push" | |
] | |
def requestBody = RequestBody.create(JSON, JsonOutput.toJson(body)); | |
Request request = new Request.Builder() | |
.url("https://api.pushbullet.com/v2/ephemerals") | |
.post(requestBody) | |
.header("Access-Token", PUSHBULLET_ACCESS_TOKEN) | |
.build() | |
def response = client.newCall(request).execute() | |
response.body().close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment