R 错误,我的 sendMessage 函数无法正常工作,有什么想法吗?

问题描述 投票:0回答:1

我在与 API 交互时在 R 中运行发送消息功能时遇到问题。看看最后一行,看看我哪里搞砸了。总是出现这个错误:

找不到函数“sendMessage”。

我尝试更新软件包并重新启动 R Studio,但没有成功。不断出现同样的错误。

#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)

我得到的确切错误:

找不到函数“sendMessage”

r sendmessage renv
1个回答
0
投票

你可以试试这个:

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

© www.soinside.com 2019 - 2024. All rights reserved.