Giter Site home page Giter Site logo

Comments (12)

ManoharLakkoju-MSFT avatar ManoharLakkoju-MSFT commented on June 2, 2024

@oadrian2
Thanks for your feedback! We will investigate and update as appropriate.

from azure-docs.

AjayKumar-MSFT avatar AjayKumar-MSFT commented on June 2, 2024

Your feedback has been shared with the content owner for further review. Thanks again for the feedback!

from azure-docs.

JialinXin avatar JialinXin commented on June 2, 2024

@oadrian2 I'm not quite understand your question. SWA only support HttpTrigger, that's why Web PubSub has a WebPubSubContext to deserialize the Web PubSub service http request to Web PubSub protocol input object. What do you mean by tie event message to CosmosDB input? Why you need to make it a CosmosDB input when the request is actually from Web PubSub service?

from azure-docs.

oadrian2 avatar oadrian2 commented on June 2, 2024

I'm referring to cosmos DB inputs rather than triggers. Basically a way of a database query based on the event that was triggering of the web pub/sub similar to how you would with an HTTP request. With SignalR triggers, the parameters on the invocation can be mapped to cosmos DB bindings on the input which allows you to retrieve the data without having to actually invoke the client yourself.

from azure-docs.

JialinXin avatar JialinXin commented on June 2, 2024

Sorry I still couldn't get your idea. Would you share a sample code, maybe SignalR one that meet your ask?

from azure-docs.

oadrian2 avatar oadrian2 commented on June 2, 2024

This is the doing a pseudo-patch operation, which is invoked through a SignalR trigger. Non-relevant code has been omitted. Let me know if you want further clarification on anything. Thank you for taking the time.

const updateTokenInput = input.cosmosDB({
  databaseName: DATABASE_NAME,
  collectionName: TOKENS_CONTAINER,
  connectionStringSetting: 'CosmosDBConnection',
  id: '{token.id}', // using token triggerMetadata (see below)
  partitionKey: '{mapId.game}', // using mapId triggerMetadata (see below)
});

//
app.generic('updateToken', {
  trigger: trigger.generic({
    type: 'signalRTrigger',
    hubName: 'map',
    category: 'messages',
    event: 'updateToken',
    // parameter names here will bind the arguments of the invoke to trigger bindings usable by inputs/outputs
    parameterNames: ['mapId', 'token'], 
  }),
  extraInputs: [updateTokenInput],
  extraOutputs: [signalRMessagesOutput, tokenContainerOutput],
  handler: async (_request, context) => {
    const mapId = context.triggerMetadata!.mapId as { id: string; game: string }; // id coming from patch request
    const token = context.triggerMetadata!.token as Token`; // patch data

    const { id: map, game } = mapId;
    const documentIn = (context.extraInputs.get(updateTokenInput) || {}) as object;
    const documentOut = { ...documentIn, ...token };

    context.extraOutputs.set(tokenContainerOutput, documentOut);
    context.extraOutputs.set(signalRMessagesOutput, [
      {
        target: 'tokenUpdated', // event name
        arguments: [mapId, documentOut], // arguments to event
      },
    ]);
  },
});

from azure-docs.

JialinXin avatar JialinXin commented on June 2, 2024

When work with WebPubSubTrigger, triggerMetadata is all the metadata pre-bind with it, where you can refer to section https://learn.microsoft.com/en-us/azure/azure-web-pubsub/reference-functions-bindings?tabs=csharp#usages about available items under different requests.

Example:
image

I'm working on a chat sample under v4 model. And probably would help you easier get started.

from azure-docs.

JialinXin avatar JialinXin commented on June 2, 2024

You can refer to this chat sample: https://github.com/JialinXin/azure-webpubsub/tree/jixin/v4-js/samples/functions/js/simplechat_v4

from azure-docs.

oadrian2 avatar oadrian2 commented on June 2, 2024

When work with WebPubSubTrigger, triggerMetadata is all the metadata pre-bind with it, where you can refer to section https://learn.microsoft.com/en-us/azure/azure-web-pubsub/reference-functions-bindings?tabs=csharp#usages about available items under different requests.

Example: image

I'm working on a chat sample under v4 model. And probably would help you easier get started.

What about in the SWA-style HTTP triggers?

from azure-docs.

JialinXin avatar JialinXin commented on June 2, 2024

Then you need to work with WebPubSubContext input binding and in the function, you can get the values by context.extraInputs.get('wpsContext'). And inner structure is described here: https://learn.microsoft.com/en-us/azure/azure-web-pubsub/reference-functions-bindings?tabs=csharp#webpubsubcontext-1

For example:

const wpsContext= input.generic({
    type: 'webPubSubContext',
    name: 'wpsContext',
    hub: 'sample_funcchatv4'
});

app.http('message', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    extraInputs: [wpsContext],
    handler: async (request, context) => {
        let wpsRequest = context.extraInputs.get('wpsContext').request;
        let data = request.data;
        ....
    },
});

from azure-docs.

oadrian2 avatar oadrian2 commented on June 2, 2024

Then you need to work with WebPubSubContext input binding and in the function, you can get the values by context.extraInputs.get('wpsContext'). And inner structure is described here: https://learn.microsoft.com/en-us/azure/azure-web-pubsub/reference-functions-bindings?tabs=csharp#webpubsubcontext-1

For example:

const wpsContext= input.generic({
    type: 'webPubSubContext',
    name: 'wpsContext',
    hub: 'sample_funcchatv4'
});

app.http('message', {
    methods: ['GET', 'POST'],
    authLevel: 'anonymous',
    extraInputs: [wpsContext],
    handler: async (request, context) => {
        let wpsRequest = context.extraInputs.get('wpsContext').request;
        let data = request.data;
        ....
    },
});

Is it the case that since the WebPubSubContext is an input and not a trigger, the trigger metadata isn't present like they are with the WebPubSubTrigger? If they aren't there when using WebPubSubContext then you can't use those values to populate other Input bindings (e.g., CosmosDB or Storage) since there isn't any binding metadata. This does limit its usefulness.

from azure-docs.

JialinXin avatar JialinXin commented on June 2, 2024

It's correct that WebPubSubContext is an input binding instead of trigger binding, so triggerMetadata is not valid for building WebPubSub metadata here. I'm not sure that if it's possible to bind single request to multiple input bindings. When you work with WebPubSubContext, it means the request is a Web PubSub request, why would you treat it as a Cosmos DB document? Should it read the request and then convert to a Cosmos DB document in other way? Would you describe your scenario a little bit more?

from azure-docs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.