Last active
January 31, 2024 11:13
-
-
Save fidadoma/57c1f310923ee26a1a8c5b8be2e012d7 to your computer and use it in GitHub Desktop.
short script to send sms using gosms.cz (czech numbers)
This file contains hidden or 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
# the following script worked Feb-2024, not sure, whether the API wont change | |
# it is pretty cheap - 1CZK per message (again, this could be cheaper with better pricing plan) | |
library(tidyverse) | |
library(httr2) | |
# you need to register for gosms.eu | |
# you will need your client_id, client_secret and channel_id | |
# store those in variables | |
client_id <- "your client id" | |
client_secret <- "your secret" | |
channel_id <- "your channel id" | |
# authenticate ------------------------------------------------------------ | |
## Get the authorization code | |
# url for authentication | |
url <- "https://app.gosms.eu/oauth/v2/token" | |
# Set up the request | |
request <- request(url) %>% | |
req_method("POST") %>% | |
req_body_form( | |
client_id = client_id , | |
client_secret = client_secret, | |
grant_type = "client_credentials" | |
) | |
# Perform the request | |
response <- req_perform(request) | |
# get access token | |
access_token_raw <- response %>% resp_body_json() | |
access_token <- access_token_raw$access_token | |
# now, we are authenticated for 1 hour | |
# send message ------------------------------------------------------------ | |
# this is a message that you want to send | |
sms_data <- list( | |
message = "Hello World!", # here is the messaage | |
recipients = c("+420000000000"), # here is a list of numbers | |
channel = channel_id # this is channel | |
) | |
# url for sending messages | |
url <- "https://app.gosms.eu/api/v1/messages" | |
# Set up the request | |
request <- request(url) %>% | |
req_method("POST") %>% | |
req_headers(`Authorization` = sprintf("Bearer %s", access_token), | |
`Content-Type` = "application/json") %>% | |
req_body_json(sms_data) | |
req_perform(request) | |
# and that it is! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment