twilio-labs / twilio-firebase-extensions

A collection of Firebase Extensions for Twilio functionality.
https://www.twilio.com/docs/labs/firebase-extensions
Apache License 2.0
15 stars 10 forks source link

ext-{EXT_INSTANCE_ID}- cloud functions prefix? #34

Closed sashatc closed 5 months ago

sashatc commented 1 year ago

Not sure if it is just me or this is smth new in how firebase extensions are deployed, but after installing via console Firebase has created functions with names prefixed with "ext-send-message-"

While it does not affect triggering processQueue function on document writes, it very much does so screws statusCallback URL formation and subsequent miss, resulting in twilio backend invoking wrong URL -> 400 Bad Request response.

sashatc commented 1 year ago

upon manually hacking processQueue to use "ext-send-message-" prefix for webhook callback URL all works ok, so the only issue is function getFunctionsUrl(functionName)

philnash commented 1 year ago

Oh, that sounds like something new. I'll take a look into it.

Thanks for letting me know!

kirill-kosov commented 1 year ago

@philnash are there any updates on this issue? We are also seeing errors in Twilio logs trying to call the statusCallback endpoint, while the actual endpoint created by the extension is ext-send-message-statusCallback.

philnash commented 1 year ago

Apologies, I've not had the chance to fix this yet. Also, I was recently affected by the recent Twilio layoffs so someone else from the team will have to look into it from now on.

sprechu commented 1 year ago

Any updates on this issue? I'm testing the Twilio Firebase Extension and I am also seeing errors in Twilio logs trying to call the statusCallback endpoint, while the actual endpoint created by the extension is ext-send-message-statusCallback. Is there any workaround I can do meanwhile?

philnash commented 1 year ago

Hi @sprechu, as per the message above, I no longer work for Twilio and can’t help here.

sprechu commented 1 year ago

Yes, I've got it ... I've opened a ticket on Twilio Support linking this issue thread ... hoping this will help. Thanks anyway for replying.

sashatc commented 1 year ago

as a workaround - give Twilio what it wants (make sure you are doing it in the correct GCP project)

  1. go to https://console.cloud.google.com/functions/ and find your existing ext-send-message-statusCallback
  2. make a copy of it and name it statusCallback

should do the trick, don't forget to verify all security access, secrets and ENV variables to be copied as well

Alternatively you can go and edit your original ext-send-message-statusCallback

  1. go to https://console.cloud.google.com/functions/ and find your existing ext-send-message-statusCallback, click on it
  2. select Source tab
  3. find src/utils.ts and function export function
getFunctionsUrl(functionName: string): string {
  if (process.env.IS_FIREBASE_CLI) {
    const baseUrl = process.env.HTTP_TUNNEL
      ? `https://${process.env.HTTP_TUNNEL}/`
      : "http://localhost:5001/";
    return `${baseUrl}${config.projectId}/${config.location}/${functionName}`;
  } else {
    return `https://${config.location}-${config.projectId}.cloudfunctions.net/${functionName}`;
  }
}

change it to

getFunctionsUrl(functionName: string): string {
  if (process.env.IS_FIREBASE_CLI) {
    const baseUrl = process.env.HTTP_TUNNEL
      ? `https://${process.env.HTTP_TUNNEL}/`
      : "http://localhost:5001/";
    return `${baseUrl}${config.projectId}/${config.location}/${functionName}`;
  } else {
    return `https://${config.location}-${config.projectId}.cloudfunctions.net/ext-send-message-${functionName}`;
  }
}
  1. I'm almost certain that GCP will not compile ts into js build, so also change compiled lib/utils.js version for it. Change it from
function getFunctionsUrl(functionName) {
    if (process.env.IS_FIREBASE_CLI) {
        const baseUrl = process.env.HTTP_TUNNEL
            ? `https://${process.env.HTTP_TUNNEL}/`
            : "http://localhost:5001/";
        return `${baseUrl}${config_1.default.projectId}/${config_1.default.location}/${functionName}`;
    }
    else {
        return `https://${config_1.default.location}-${config_1.default.projectId}.cloudfunctions.net/${functionName}`;
    }
}

to

function getFunctionsUrl(functionName) {
    if (process.env.IS_FIREBASE_CLI) {
        const baseUrl = process.env.HTTP_TUNNEL
            ? `https://${process.env.HTTP_TUNNEL}/`
            : "http://localhost:5001/";
        return `${baseUrl}${config_1.default.projectId}/${config_1.default.location}/ext-send-message-${functionName}`;
    }
    else {
        return `https://${config_1.default.location}-${config_1.default.projectId}.cloudfunctions.net/${functionName}`;
    }
}
sprechu commented 1 year ago

Hi @sashatc, thanks for your help. I applied the workaround solution you suggestd (2nd option, ie. adding prefix ext-send-message- in utils.ts and utils.js) in the ext-send-message-statusCallack function, but nothing changes ... I needed to make the same modifications also in the ext-send-message-processQueue function to see finally the extension working correctly.

edmundsiah81 commented 1 year ago

@sprechu I faced the same issues, after changing both utils.ts and utils.js, it still doesn't work. Able to share what modifications do you make in ext-send-message-processQueue function?

edmundsiah81 commented 1 year ago

Managed to get it works, for others who faced the same issue, you need to go to back functions of processQueue & statusCallback, not the processqueue.js or processqueue.ts

druv5319 commented 5 months ago

fixed #101