interval / interval-node

The official Interval SDK for Node.
https://interval.com/docs
121 stars 13 forks source link

get id from routing path #29

Closed well-balanced closed 1 year ago

well-balanced commented 1 year ago

Hi, thanks for making great tools :) I wonder if there is a way to dynamically deliver ID values to the routing path and get them. are there any solutions?

alexarena commented 1 year ago

Hi! I believe what you're looking for is context params. Inside of an action, you can use them like this:

import { Action, io, ctx } from "@interval/sdk";

export default new Action({
  name: "User ID lookup tool",
  handler: async () => {
    let userId = ctx.params.userId
    if (!userId) {
      userId = await io.input.text("User ID to lookup")
    }
    // ... rest of your action
  },
});

If you went to the URL of your action and added ?userId=abc as a query param, that would be passed into this action as ctx.params.userId.

Assuming this answers your question, I'm going to close the issue, but feel free to reopen if it didn't!