Discourse Webhooks and Zapier


(Jay Pfaffman) #21

Hey, @fantasticfears. I’ve a client who wants to email new users, so this seems to fit the bill.

Does this plugin still work? I see that the user created webhook is added, but it doesnt’ seem to be getting triggered.

I invited a couple users on a closed site and it didn’t get triggered when they logged in with an invite URL nor when they clicked the activation link in email or the activate account button.


(Erick Guan) #22

The plugin isn’t updated for a long time but it should. I didn’t verify that. Perhaps you can find clues in /logs. It should be triggered when they clicked the invite link.


(Pad Pors) #23

the plugin (user created webhook) doesn’t work currently. there is no trigger for new registered users and nothing in the /log.


Webhook for new users
#25

Man, this is a real disappointment. I thought I’d found the solution to my email problems. Anybody able to figure out what’s going on with the plugin and get it fixed?

Ok. That’s a really simple plugin. Unfortunately I don’t know Ruby or how Discourse works under the hood, so I can’t fix it, but I imagine that somebody who does could find the issue and fix it in less than 15 minutes, assuming Discourse didn’t make some major changes.


(Erick Guan) #26

Do you check the user created type in the configuration panel?


(Pad Pors) #27

I guess you mean something like this:

yes, it has been checked.


(Erick Guan) #28

Please try the new build.


(Pad Pors) #29

thanks for the update, but it doesn’t seem to work correctly (at least for me).

when a new user is created nothing happens for the webhook, it only respond “ok” to pings.


(Erick Guan) #30

If so, I need to look into this. Are you willing to sponsor $100 for a migration?


(Uwe Keim) #31

I’ve successfully managed to use this to post new topics to Twitter.

I was confused that the Webhook does not send the full URL of the topic to Zapier.

Although I managed to manually build the URL, I would love to have on single field with the full absolute topic URL delivered by the Webhook.

Is this possible?


(Simon Cossar) #32

This is late for a reply, but I spent some time today working on this. To get access to the header, follow the steps outlined in the OP - select “Catch Raw Hook” and then add a filter. Configure the filter to only continue if the Headers Http X Discourse Event matches the event you are looking for.

The difficulty I had was that the Catch Raw Hook passes the webhook’s raw body. The final action I’m using needs parsed data from the body. What is working for me is to add a Code action after the filter. On the Code Action modal, select “Run Javascript”:

Zapier will create an inputData object that you can add named properties to. Add a name for your property in the left column. From the right column, select “Catch Raw Hook” from the dropdown menu, and then select “Raw Body”:

Scroll down the page to see a code input:

You then need to replace the sample code with some code that parses the Raw Body and returns an object that has the values you need for your final action. Here’s the code I’m using. The object it returns is being used by the Salesforce integration. Salesforce requires a last name, so if no last name exists, an error is returned:

const parsed = JSON.parse(inputData.raw);
if (parsed.user) {
  const user = parsed.user,
        name = user.name,
        userFields = user.user_fields;
  let firstName,
      lastName,
      company;
  
  if (name) {
    const splitName = name.split(' ');
    firstName = splitName[0];
    lastName = splitName[1]
    }
  if (userFields) {
    company = userFields['10'];
  }
  if (lastName) {
    return {id: user.id,
            username: user.username,
            lastName: lastName,
            firstName: firstName,
            email: user.email,
            company: company
           };
  } else {
    return {error: "Missing last name"}
  }
} else {
  return {error: "A user object was not returned"};
}

To avoid making a failed request in the final action, another Zapier filter can be added. Set that filter to only continue if the error field returned by the javascript does not exist:

You can then add your final action. For selecting the fields to be used in the final action, use the properties returned by the Run Javascript action.

If anyone knows of a more straightforward way of doing this, let me know.


(cosmo) #33

Request:

New trigger category:
Log events

User selects which log events trigger webhhooks. Then set up appropriate zaps.

Basically a way for admins to keep an eye on whatever selected log events that occur.
Ie, impersonate user, check private message.

Instead of having to always go look, this is a kind of way to create a notification of watched admin actions amongst other admins


(Mark) #34

I’m struggling with extracting the data from the raw body in Zapier too. All I need is the username value from the user_created event.

Am I right in thinking the only way you’ve managed to extract values from the raw body text @Simon_Cossar is with javascript?

(Sorry for dragging up old thread)


(Simon Cossar) #35

Yes, I recently looked at this again. If you need to use the “Catch Raw Hook” trigger, the only way I’ve found to extract the data from the raw body text is by adding a code step and extracting the data with javascript.


(Mark) #36

I actually solved my issue of having too much data in the raw body text without using code, just using standard Zapier steps:

  • Stripped out the quotation marks
  • Replaced colons with commas
  • Cleaned up front end of the data to basically look like a long list of comma separated values (removed all the '{'s)
  • Used split text, separated by comma, using custom value (3) for segment index to get the username out