R error my sendMessage function is not working any ideas why?

67 views Asked by At

I'm having an issue running the send message function in R while interfacing with my API. See the last line to see where I'm messing up. Always get this error:

could not find function "sendMessage".

I have tried updating the package and restarting R Studio but that has not worked. Keep getting the same error.

#libraries----
library(httr)
library(httr2)
library(stringr)
library(jsonlite)
library(tidyverse)
library(magrittr)
library(quantmod)
library(telegram.bot)
# API Requests using GET function----
base_url = "https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest"
api_key <- "a7e1626a-e2df-47d5-8e51-18eb23c4fd05"
response = GET(
  base_url,
  query = list(
    start = "1",
    limit = "10",
    convert = "USD"
  ),
  add_headers('X-CMC_PRO_API_KEY' = api_key
  ))

# Handle responses with content function and view data structure----

coinmarketcap_data <- content(response, "text") 

parsed_data <- fromJSON(coinmarketcap_data, flatten = TRUE) 

str(parsed_data)



# example: extracting the names of the first 10 crypto-----

cryptocurrencies <- as.data.frame(parsed_data$data) 

# initialize telegram bot-----
Sys.setenv(TELEGRAM.BOT.TOKEN = "6411813250:AAGsh0OSuu7rHF1t4Q4Wlq1P0F-TGZAknoc")
bot_token <- Sys.getenv("TELEGRAM.BOT.TOKEN")

crypto_bot <- Bot(token = bot_token)
message_text <- paste("Top 10 crypto:\n", cryptocurrencies$name, collapse = "\n")
chat_id <- "6220048556"

sendMessage(token = crypto_bot, text = message_text, chat_id = chat_id)

Exact error I'm getting:

could not find function "sendMessage"

1

There are 1 answers

0
Erfan Ghasemi On

You could try this: crypto_bot$sendMessage( text = message_text, chat_id = chat_id)