How to Create a Slack Message from OpenAI Multi-line Response - Make.com Guide

Have you ever tried to create a Slack message from a multi-line response from OpenAI and found that the JSON breaks? Well, you're not alone. This is a common problem that many Make.com users face. But don't worry, there's a solution.

Problem

The issue arises when the response from OpenAI is in multiple lines. This breaks the Slack JSON, making it impossible to create a Slack message from the response.

Solution

The quick and dirty solution is to replace every newline with an empty string. Here's how you can do it:

Copy paste to scenario: {{replace(1.text; newline; emptystring)}}

However, this might not always work. If you've been trying to use \n and it's not working, you're not alone. Many users have faced this issue.

But there's a better solution. You can use the following code to get the job done:

{{replace(decodeURL(replace(encodeURL(2.choices[].message.content); "%0A"; "\n")); "\""; )}}

Troubleshooting Tips

If you're still facing issues, make sure you're using the correct variables. Only certain variables are available to be replaced. If you're not sure which ones are available, you can check the list of replaceable variables.

Conclusion

Creating a Slack message from a multi-line response from OpenAI can be tricky, but with the right code, it's possible. Remember to replace every newline with an empty string and use the correct variables. With these tips, you should be able to create your Slack message without any issues.

You do have further questions?

Ask your question via E-Mail: Richard@make-app.de
Book a paid Support & Consulting Session
New Make.com user? Sign up through this Affiliate Link to receive 10.000 operations for FREE.