This gist uses node-imessage
npm install -g imessage
$ imessagejs recipients "name or number"
Copy the id
$ imessagejs search "http" --recipient $IDHERE | grep http | sed "s/.*\(http.*\)/\1/" | sed "s/\(http.*\)\ .*/\1/"
You can output it in JSON
$ imessagejs search "http" --recipient $IDHERE --json | grep http | sed "s/.*\(http.*\)/\1/" | sed "s/\(http.*\)\ .*/\1/"
if someone could improve the regexp, that would be great :)