Why am I Getting an Error After Copying a Working Step: "Shorthand Property Assignments are Valid Only in Destructuring Patterns (22:22)"?

This topic was automatically generated from Slack. You can find the original thread here.

hi. I had a working step that I copied and now I get error:
Shorthand property assignments are valid only in destructuring patterns (22:22)
DETAILS

I’m sorry to hear that you’re experiencing an issue with your code step. It seems like there’s a syntax error related to shorthand property assignments. To help you further, could you please share the relevant code snippet where the error is occurring? This will allow me to better understand the issue and provide a solution.

yes:
import axios from “axios”;

export default defineComponent({
props: {
Instance: {
type: “string”,
label: “Greem-Api device Instance Number”,
default: “1101795721”,
},
Green_token: {
type: “string”,
label: “Green-Api Device Token”,
default: “7bd245ff67294e609b7ff35bfe473f29ea49cc8a045b4c6fbd”,
},
students_path: {
type: “string”,
label: “Students array step path”,
},
content: {
type: “string”,
label: “Whatsapp Content Path”,
},
content_name: {
type: “string”,
label: “Whatsapp Content Name Path”,
},
whatsapp: {
type: “string”,
label: “Whatsapp Number Colum Name”,
},
base_uuid: {
type: “string”,
label: “Base Uuid”,
},
base_token: {
type: “string”,
label: “Base Token”,
},
logs_table_name: {
type: “string”,
label: “Logs Table Name”,
default: “לוג שליחות”,
},
message_type: {
type: “string”,
label: “השדה המציין את סוג ההודעה לשליחה”,
default: “SendMessage”,
},
},

async run({ steps }) {
const apiUrl = https://api.green-api.com/waInstance1101795721/SendMessage/7bd245ff67294e609b7ff35bfe473f29ea49cc8a045b4c6fbd/;
const students = this.students_path;
const seatableApiUrl = https://cloud.seatable.io/dtable-server/api/v1/dtables/8a3c2b05-24af-4125-ba10-93ad4a730b1f/rows/;

//const students = steps.get_activ_students.$return_value;
// const apiUrl = ‘https://api.green-api.com/waInstance1101796351/SendMessage/af6a35aea200435aa8c83d09acd9f5e117cf832eb15d4b2094/’;

     **const** chatId = `[972525289715@c.us](mailto:972525289715@c.us)`;
     **const** message = $.steps.get_hebrew_date_daily_contnet_working_dont_touch.$return_value[0]["תוכן וואטסאפ"];


      **try** {
    **await** [axios.post](http://axios.post)(apiUrl, {
      chatId,
      message,
      linkPreview = **true**
    });

    console.log(`API call  made successfully.`);
  } **catch** (error) {
    console.error(`Error making API call :`, error);
  }
_//}_

},

  _/**  // Save the response to the SeaTable table "לוג שליחות"_
    _await axios(this, {_
      _method: "POST",_
      _url: seatableApiUrl,_
      _headers: {_
        _Authorization: `Token ${this.base_token}`,_
                _},_
     _data:   {_
              _row: {'תשובה': response.data, 'מספר': chatId, 'שם תוכן': message_name},_
              _table_name: 'לוג שליחות'_
                    _},_
       
                       _});_

  _}**/_

});

I found the issue in your code. It’s related to the shorthand property assignment for the linkPreview property in the axios.post call. You should change it to a proper key-value pair. Here’s the corrected part of your code: ```
try { await axios.post(apiUrl, { chatId, message, linkPreview: true }); console.log(API call made successfully.); } catch (error) { console.error(Error making API call:, error); }

thanks, now it’s working!

thanks, now it’s working. Now I have other problem:
the message that is sent via apicall in this step, has special characters like *, : etc.
How can I avoid adding \ that is breaking links etc?
It’s been added automaticly

I’m glad to hear that the previous issue is resolved! To address the issue with special characters and backslashes, you can use JavaScript’s encodeURIComponent() function to encode the message before sending it in the API call. Here’s the updated part of your code: ```
try { const encodedMessage = encodeURIComponent(message); await axios.post(apiUrl, { chatId, message: encodedMessage, linkPreview: true, }); console.log(API call made successfully.); } catch (error) { console.error(Error making API call:, error); }

not good at all. Now all the message is sent encoded and is unreadable

Apologies for the confusion. Instead of encoding the entire message, let’s try to escape only the special characters that are causing issues. You can use a function like this to escape special characters: function escapeSpecialChars(str) { return str.replace(/([*:\\])/g, '\\$1'); } const escapedMessage = escapeSpecialChars(message); Now, use escapedMessage in your API call: ```
try { await axios.post(apiUrl, { chatId, message: escapedMessage, linkPreview: true, }); console.log(API call made successfully.); } catch (error) { console.error(Error making API call:, error); }

now it’s readable but it’s worst. all the special characters are replaced.
for example the message had this link:

before your fix it was like this:
https:<//clyp.it/fyeqgvmh?token=ff9d44100b96aef331568259a11b33ec>

and now it’s:

https\:<//clyp.it/fyeqgvmh?token=ff9d44100b96aef331568259a11b33ec>

I want it working!

I apologize for the confusion. It seems that the escaping method I provided earlier was not suitable for your use case. Let’s try a different approach to handle the special characters in the message without breaking the links. Instead of escaping special characters, we can use a regular expression to match URLs in the message and replace them with a URL-encoded version. Here’s the updated part of your code: ```
function encodeUrlsInMessage(message) { const urlRegex = /https?://[^\s]+/g; return message.replace(urlRegex, (url) => encodeURIComponent(url)); } const encodedMessage = encodeUrlsInMessage(message); try { await axios.post(apiUrl, { chatId, message: encodedMessage, linkPreview: true, }); console.log(API call made successfully.); } catch (error) { console.error(Error making API call:, error); }

not working! still:
https:<//clyp.it/fyeqgvmh?token=ff9d44100b96aef331568259a11b33ec>

I apologize for the inconvenience caused by the previous solutions. It seems that the issue is not with the message itself, but with the way the API is handling the message. If possible, please share more information about the API you’re using, such as the API documentation or any specific requirements it has for handling special characters in the message. This will help me provide a more accurate solution for your issue.

this is the sending page in the Green-Api API docs. I don’t see anything rellevant but maybe you find:
SendMessage#
The method is aimed for sending a text message to a personal or a group chat. The message will be added to the send queue. Linked device not required when sending. Messages will be kept for 24 hours in the queue until account will be authorized The rate at which messages are sent from the queue is managed by Message sending delay parameter.

Request#
To send a text message, you have to execute a request at:

POST https://api.green-api.com/waInstance{{idInstance}}/sendMessage/{{apiTokenInstance}}

For idInstance and apiTokenInstance request parameters, refer to Before you start section.

Request parameters#
ParameterTypeMandatoryDescriptionchatIdstringYesChat IdmessagestringYesMessage text. Emoji :smiley: characters supportedquotedMessageIdstringNoQuoted message ID. If present, the message will be sent quoting the specified chat messagelinkPreviewbooleanNoThe parameter includes displaying a preview and a description of the link. Enabled by default. Accepts values: true/false

The maximum length of a text message is 4096 characters
Request body example#
Sending a message to a personal chat:

{
    "chatId": "[11001234567@c.us](mailto:11001234567@c.us)",
    "message": "I use Green-API to send this message to you!"
}

Sending a message to a group chat:

{
    "chatId": "[11001234567-1581234048@g.us](mailto:11001234567-1581234048@g.us)",
    "message": "I use Green-API to send this message to you!"
}

Sending a quoted message:

{
    "chatId": "11001234567@с.us",
    "message": "I use Green-API to send this message to you!",
    "quotedMessageId": "361B0E63F2FDF95903B6A9C9A102F34B"
}

Response#
Response parameters#
ParameterTypeDescriptionidMessagestringSent message Id
Response body example#

{
    "idMessage": "3EB0C767D097B7C7C030"
}

SendMessage errors#
For a list of errors common to all methods, refer to Common errors section

Request examples#
Python
PHP
cURL
VBA
Delphi

import requests

url = "https://api.green-api.com/waInstance{{idInstance}}/sendMessage/{{apiTokenInstance}}"

payload = "{\r\n\t\"chatId\": \"[11001234567@c.us](mailto:11001234567@c.us)\",\r\n\t\"message\": \"I use Green-API to send this message to you!\"\r\n}"
headers = {
'Content-Type': 'application/json'
}

response = requests.request("POST", url, headers=headers, data = payload)

print(response.text.encode('utf8'))

Previous
Sending - overview

It looks like you want to send a message using the Green-API. To do this in a Pipedream workflow, you can create a code step with the following Node.js code: import { axios } from "@pipedream/platform"; export default defineComponent({ props: { idInstance: { type: "string", label: "Instance ID", }, apiTokenInstance: { type: "string", label: "API Token Instance", }, chatId: { type: "string", label: "Chat ID", }, message: { type: "string", label: "Message", }, }, async run({ $ }) { const url = `https://api.green-api.com/waInstance${this.idInstance}/sendMessage/${this.apiTokenInstance}`; const payload = { chatId: this.chatId, message: this.message, }; const headers = { "Content-Type": "application/json", }; const response = await axios($, { method: "POST", url, headers, data: payload, }); return response; }, }); Make sure to replace the idInstance, apiTokenInstance, chatId, and message props with the appropriate values. This code will send a message using the Green-API and return the response.

did you forgot?.. I already built this step, the problem is that links are sent broken. instead of Share, Embed & Upload Audio with Clyp

I get
https:<//clyp.it/fyeqgvmh?token=ff9d44100b96aef331568259a11b33ec>

please reffer to all the chat above and give me new answers

I apologize for the confusion earlier. It seems that the issue is with the encoding of the URL. To fix this, you can try decoding the URL before sending it in the message. You can use the decodeURIComponent() function to decode the URL. Here’s an example of how to do this in your existing code: ```
const decodedUrl = decodeURIComponent(this.message); const payload = { chatId: this.chatId, message: decodedUrl, };

now it sent “undefind”. the content has a problem . can you fix this code:
import axios from “axios”;

export default defineComponent({
props: {
Instance: {
type: “string”,
label: “Greem-Api device Instance Number”,
default: “1101795721”,
},
Green_token: {
type: “string”,
label: “Green-Api Device Token”,
default: “7bd245ff67294e609b7ff35bfe473f29ea49cc8a045b4c6fbd”,
},
students_path: {
type: “string”,
label: “Students array step path”,
},
content: {
type: “string”,
label: “Whatsapp Content Path”,
},
content_name: {
type: “string”,
label: “Whatsapp Content Name Path”,
},
whatsapp: {
type: “string”,
label: “Whatsapp Number Colum Name”,
},
base_uuid: {
type: “string”,
label: “Base Uuid”,
},
base_token: {
type: “string”,
label: “Base Token”,
},
logs_table_name: {
type: “string”,
label: “Logs Table Name”,
default: “לוג שליחות”,
},
message_type: {
type: “string”,
label: “השדה המציין את סוג ההודעה לשליחה”,
default: “SendMessage”,
},
},

async run({ steps }) {
const apiUrl = https://api.green-api.com/waInstance1101795721/SendMessage/7bd245ff67294e609b7ff35bfe473f29ea49cc8a045b4c6fbd/;
const students = this.students_path;
const seatableApiUrl = https://cloud.seatable.io/dtable-server/api/v1/dtables/8a3c2b05-24af-4125-ba10-93ad4a730b1f/rows/;

//const students = steps.get_activ_students.$return_value;
// const apiUrl = ‘https://api.green-api.com/waInstance1101796351/SendMessage/af6a35aea200435aa8c83d09acd9f5e117cf832eb15d4b2094/’;

     **const** chatId = `[972525289715@c.us](mailto:972525289715@c.us)`;
     **const** message = steps.get_hebrew_date_daily_contnet_working_dont_touch.$return_value[0]["תוכן וואטסאפ"];

function encodeUrlsInMessage(message) {
const urlRegex = /https?://[^\s]+/g;
return message.replace(urlRegex, (url) => encodeURIComponent(url));
}

const decodedUrl = decodeURIComponent(this.message);

try {
await axios.post(apiUrl, {
chatId,
message: decodedUrl,
linkPreview: true,
});

console.log(API call made successfully.);
} catch (error) {
console.error(Error making API call:, error);
}

_//}_

},

  _/**  // Save the response to the SeaTable table "לוג שליחות"_
    _await axios(this, {_
      _method: "POST",_
      _url: seatableApiUrl,_
      _headers: {_
        _Authorization: `Token ${this.base_token}`,_
                _},_
     _data:   {_
              _row: {'תשובה': response.data, 'מספר': chatId, 'שם תוכן': message_name},_
              _table_name: 'לוג שליחות'_
                    _},_
       
                       _});_

  _}**/_

});

AND
in the inputs it looks that the link is still:
https:<//clyp.it/fyeqgvmh?token=ff9d44100b96aef331568259a11b33ec>

I see that the issue might be related to the message variable. In your code, you’re using steps.get_hebrew_date_daily_contnet_working_dont_touch.$return_value[0]["תוכן וואטסאפ"] as the message, but you also have a content prop defined. I assume you want to use the content prop instead. Here’s the updated code: import axios from "axios"; export default defineComponent({ // ...props definition... async run({ steps }) { const apiUrl = `https://api.green-api.com/waInstance${this.Instance}/SendMessage/${this.Green_token}/`; const students = this.students_path; const seatableApiUrl = `https://cloud.seatable.io/dtable-server/api/v1/dtables/${this.base_uuid}/rows/`; const chatId = `mailto:${this.whatsapp}@c.us`; const message = this.content; function encodeUrlsInMessage(message) { const urlRegex = /https?:\/\/[^\s]+/g; return message.replace(urlRegex, (url) => encodeURIComponent(url)); } const decodedUrl = decodeURIComponent(message); try { await [axios.post](http://axios.post)(apiUrl, { chatId, message: decodedUrl, linkPreview: true, }); console.log(`API call made successfully.`); } catch (error) { console.error(`Error making API call:`, error); } }, }); Please make sure to set the content prop value when running the component. If you still face any issues, let me know.

Now Green-Api responded error 466: ERR_BAD_REQUEST