Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use custom function created in Javascript Adaptive Cards in UI Template Schema. #8876

Open
gaurav-simpplr opened this issue Apr 18, 2024 · 0 comments

Comments

@gaurav-simpplr
Copy link

gaurav-simpplr commented Apr 18, 2024

Target Application

For my own application

Application Operating System

Linux

Schema Version

version: "1.0"

Problem Description

I have written a custom function in Javascript for Adaptive cards. Below is an example code, how I have created it :

import { Expression } from "adaptive-expressions";

const formatOutlookDate = (args: any) => {
  const date = new Date(args[0]);
  return `Formatted Outlook Date is: ${date.toDateString()}`;
};

Expression.functions.add("formatOutlookDate", formatOutlookDate);

I'm using it my template schema as below :

{
  type: "UI Card",
  version: "1.0",
  body: [
    {
      type: "Container",
      $data: "${value}",
      items: [
        {
          type: "Container",
          items: [
            {
              type: "TextBlock",
              name: "secondary",
              color: "typeSecondary",
              text: "Outlook Calendar",
            },
            {
              type: "TextBlock",
              name: "heading5",
              weight: "bold",
              color: "typeTitleLight",

              text: "${formatOutlookDate(start.dateTime)}",
            },
          ],
        },
      ],
    },
  ],
};

const populateTemplateWithData = (schema: any, data: any) => {
  const context: ACData.IEvaluationContext = { $root: data };
  const template = new ACData.Template(schema);

  return template.expand(context);
};

Now, when I run it, it gives me error as below screenshot :
Screenshot 2024-04-18 at 12 43 22 PM

Expected Outcome

Function should work instead of giving error as 'Unknown function'

Actual Outcome

As below screenshot :

Screenshot 2024-04-18 at 12 43 22 PM

Card JSON

{
  type: "UI Card",
  version: "1.0",
  body: [
    {
      type: "Container",
      $data: "${value}",
      items: [
        {
          type: "Container",
          items: [
            {
              type: "TextBlock",
              name: "secondary",
              color: "typeSecondary",
              text: "Outlook Calendar",
            },
            {
              type: "TextBlock",
              name: "heading5",
              weight: "bold",
              color: "typeTitleLight",

              text: "${formatOutlookDate(start.dateTime)}",
            },
          ],
        },
      ],
    },
  ],
};

Repro Steps

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant