Azure / Microsoft365R

R SDK for interacting with Microsoft 365 APIs
Other
308 stars 41 forks source link

Send Adaptive Card #186

Closed MarcelHuesing closed 5 months ago

MarcelHuesing commented 10 months ago

Hello,

I recently attempted to send an adaptive card in Microsoft Teams, but I encountered the following error message:

"Error in UseMethod("normalize_src"): no applicable method for 'normalize_src' applied to an object of class 'list'"

I used the following R code:

library(jsonlite)

# Define the adaptive card as JSON
adaptive_card_json <- '{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "TextBlock",
      "text": "Hello from R!",
      "size": "large"
    }
  ]
}'

# Create the reply message with the adaptive card
reply_message <- list(
  list(
    type = "application/vnd.microsoft.card.adaptive",
    content = jsonlite::fromJSON(adaptive_card_json)
  )
)

# Send the message
msg$send_reply("Test", attachments = reply_message, content_type = "html")

Could someone please assist me with troubleshooting this error? I might have overlooked something or made a mistake.

Thank you in advance for your assistance!

hongooi73 commented 5 months ago

You could send it as an attachment, is that acceptable?

hongooi73 commented 5 months ago

Ok, looking a bit closer at your code: what you should do is save your card as a json (text) file, then send that file as an attachment. Sending the parsed JSON like that won't work.