Integrate teneo chatbot with shopify website

When you are using script nodes, the code you put in there should be Groovy. There are several ways to produce JSON in Groovy and you are getting close but you will need to do a bit more.

What it looks are doing in your script is populate the variable TestImage with JSON directly. Sadly, that will not work.

What you should do is first populate a variable inside your script with a Groovy object. The code looks very similar to your example above, but note the square brackets (also, your example above seems to use ‘curly’ quotes which can cause issues, but that may just be a result of copy/paste):

def myImageObject = [
   "type":"image",
   "image_url":"https://cdn.shopify.com/s/files/1/0423/1702/1335/products/8C65F937F11F_9100beddaf_360x.jpg?v=1593650529.jpg"
]

The code above creates a variable myImageObject and because it is preceded with the word def it is only available inside the script node. Once the script has finished, this variable is gone and the flow is no longer aware of it.

So, we now have a variable that contains a Groovy object and that will be gone once the script has finished loading. That means we have two things left to do: 1) make sure that the Groovy object is converted to JSON. 2) Make sure the JSON is stored in your flow variable TestImage so the flow can use it even after the script has finished.

We can do that like this:

TestImage = new groovy.json.JsonOutput().toJson(myImageObject)

The full script looks like this:

def myImageObject = [
  "type":"image", 
  "image_url":"https://cdn.shopify.com/s/files/1/0423/1702/1335/products/8C65F937F11F_9100beddaf_360x.jpg?v=1593650529.jpg"
]

TestImage = new groovy.json.JsonOutput().toJson(myImageObject)