please help me what am I doing wrong? Im doing telegram notifier via ruby in my Fastfile and gets that problem:
[!] Syntax error in your Fastfile on line 175: Fastfile:175: syntax error, unexpected tIDENTIFIER, expecting end
210...ication/json' --data '{"chat_id": "123456789", "media": [{"t...
211... ^~~~~~~
212Fastfile:175: syntax error, unexpected tINTEGER, expecting end
213... --data '{"chat_id": "123456789", "media": [{"type": "photo"...
214... ^~~~~~~~~
My code:
lane :detox do
images = Dir.glob("folder/*.png")
images.each do |image|
puts image
sh "curl --request POST --header 'Content-Type: application/json' --data '{"chat_id": "123456789", "media": [{"type": "photo", "media": "attach://image"}]' https://api.telegram.org/botToken/sendMediaGroup"
end
2
Answers
I see a few things wrong here. Firstly, you should escape all your quotation marks in the string following
sh
. Otherwise, the string is terminated early and you’ll encounter errors.Secondly, you opened 2
do
blocks:lane :detox do
andimages.each do |image|
, but you only have a singleend
.This should be
The syntax error is caused by using unescaped double quotes within a double quoted string:
You can escape
"
as"
but it’s often easier to use a heredoc instead which doesn’t require escaping:However, instead of building the command yourself, you can also pass the command options as separate arguments to
sh
:Which also allows you to create the JSON from a Ruby hash on the fly:
Doing so ensures that your JSON is always valid. (syntactically)