docker-icloudpd
docker-icloudpd copied to clipboard
Request to add WeCom notifications
I am sorry to request development of this notification request.
WeCom notifications is a WeChat official notification,WeChat has a lot of users. IYUU is not official. https://developer.work.weixin.qq.com/document/path/90236
Could you help to add this notification?
Notification requires 5 environment variables:
corpid
corpsecret
touser
agentid
media_id
can you help,please!
Hi,
I've added WeCom as a notification type, but I am unable to test it. Would you please let me know if it works for you?
Thanks.
Thanks for your contribution.
There is a little problem with your script about Wecom message notification, I have adjusted it. Please check the attachment.
There are some texts in it that I translated into Chinese.
When icloud_china
set to true
, can it be displayed in Chinese?
Hi,
I have a few questions.
Why has this line changed from this:
notification_result="$(curl --silent --output /dev/null --write-out "%{http_code}" --data-ascii "{\"touser\":\"@all\",\"msgtype\":\"text\",\"agentid\":\"1\",\"text\":{\"content\":\"\${wecom_text}\"},\"safe\":\"0\"}" --url "${notification_url}")"
to this?:
notification_result="$(curl --silent --output /dev/null --write-out "%{http_code}" --data-ascii "{\"touser\":\"${touser}\",\"msgtype\":\"mpnews\",\"agentid\":\"${agentid}\",\"mpnews\":{\"articles\":[{\"title\":\"iCloudPD 照片同步 - $name\",\"thumb_media_id\":\"$thumb_media_id\",\"author\":\"$author\",\"content_source_url\":\"$content_source_url\",\"content\":\"$wecom_text\",\"digest\":\"$notification_message\"}]},\"safe\":\"0\",\"enable_id_trans\":\"0\",\"enable_duplicate_check\":\"0\",\"duplicate_check_interval\":\"1800\"}" --url "${notification_url}")"
This references variables which have not been set earlier in the script: $touser, ${agentid}, $name, $author and $content_source_url. Why is that?
...also, what are these for?
# 启动、下载时使用的封面
thumb_media_id="$media_id_normal"
# cookie快要过期、删除文件时使用的封面
thumb_media_id="$media_id_delete"
# 同步失败、cookiey已过期封面
thumb_media_id="$media_id_warning"
the three media_id_* variables have not been set in the script either.
WeChat notification official document
The notification type use mpnews
is much better than pure text
. mpnews
is combination of image and text.
notification type use mpnews, need to set the environment variable:corpid(wecom_id)
corpsecret(wecom_secret)
touser
agentid
thumb_media_id
author
content_source_url
# 启动、下载时使用的封面
thumb_media_id="$media_id_normal"
# cookie快要过期、删除文件时使用的封面
thumb_media_id="$media_id_delete"
# 同步失败、cookiey已过期封面
thumb_media_id="$media_id_warning"
- Downloaded and start the container use image: normal,similar emoji ℹ \xE2\x9A\xA0
- Delete pictures use image: delete, similar emoji ⚠️ \xF0\x9F\x9A\xA8
- Synchronization failed, cookie expired use image: warning,similar emoji 🚨 \xE2\x9A\xA0
These 3 media_id_* images are stored in the wecom official server. The id of the requested image is thumb_media_id
.

Below are the environment variables for my container configuration
Hi,
I've pushed a new version, however, I've changed the notification icons slightly, so that there are additional events:
if [ "${notification_classification}" = "startup" ];then
notification_icon="\xE2\x96\xB6"
# 启动、下载时使用的封面
thumb_media_id="$media_id_normal"
elif [ "${notification_classification}" = "downloaded files" ]; then
notification_icon="\xE2\x8F\xAC"
# 启动、下载时使用的封面
thumb_media_id="$media_id_normal"
elif [ "${notification_classification}" = "cookie expiration" ]; then
notification_icon="\xF0\x9F\x9A\xA9"
elif [ "${notification_classification}" = "deleted files" ]; then
notification_icon="\xE2\x9D\x8C"
# cookie快要过期、删除文件时使用的封面
thumb_media_id="$media_id_delete"
elif [ "${notification_classification}" = "failure" ] || [ "${notification_classification}" = "cookie expired" ]; then
notification_icon="\xF0\x9F\x9A\xA8"
# 同步失败、cookiey已过期封面
thumb_media_id="$media_id_warning"
fi
Can you just re-do the translations, please?
Also, should I set thumb_media_id="$media_id_warning"
in the cookie expiration
classification, or would you want something else there?
Do you also want thumb_media_id="$media_id_normal"
for both startup
and downloaded files
classifications?
Hi,
I changed a few places slightly and retranslated in the script. Please check the attachment and update, Thanks!
sync-icloud.sh_202207211647_GMT+8.zip
You are right, there should be more events. I've changed too.
if [ "${notification_classification}" = "startup" ];then
notification_icon="\xE2\x96\xB6"
# 启动成功通知封面/Image for Startup success
thumb_media_id="$media_id_startup"
elif [ "${notification_classification}" = "downloaded files" ]; then
notification_icon="\xE2\x8F\xAC"
# 下载通知封面/Image for downloaded files
thumb_media_id="$media_id_download"
elif [ "${notification_classification}" = "cookie expiration" ]; then
notification_icon="\xF0\x9F\x9A\xA9"
# cookie即将过期通知封面/Image for cookie expiration
thumb_media_id="$media_id_expiration"
elif [ "${notification_classification}" = "deleted files" ]; then
notification_icon="\xE2\x9D\x8C"
# 删除文件通知封面/Image for deleted files
thumb_media_id="$media_id_delete"
elif [ "${notification_classification}" = "failure" ] || [ "${notification_classification}" = "cookie expired" ]; then
notification_icon="\xF0\x9F\x9A\xA8"
# 同步失败、cookiey已过期通知封面/Image for cookie expired or failure
thumb_media_id="$media_id_warning"
If use wecom notifications, the following environment variables should be set. If possible, please post it in the README, thank you!
wecom_id
: 企业ID / This is the CORPID associated with your account
wecom_secret
: 企业应用的Secret / This is the CORPSECRET associated with your account
agentid
: 企业应用的id / Enterprise application id
touser
: 接收通知的对象 / who receives notifications
content_source_url
: 阅读原文跳转链接 / Click on the page link after "reading the original text"
name
: 当前 Apple ID 所有人 / Current Apple ID owner
media_id_startup
: 启动成功通知封面 / Image for Startup success
media_id_download
: 下载通知封面 / Image for downloaded files
media_id_delete
: 删除文件通知封面 / Image for deleted files
media_id_expiration
: cookie即将过期通知封面 / Image for cookie expiration
media_id_warning
: 同步失败、cookiey已过期通知封面 / Image for cookie expired or failure
For the setting method of media_id, please check this link, thanks the author.
The media_id image I am using I will share it with friends who need it. media_id_images.zip
Just found a bug, I don't know why this happens,Another way to write it solves the problem.Please use the latest,Thanks!
sync-icloud.sh_202207211647_GMT+8.zip
When convert the notification_files_preview_text
variable separately and put it in wecom_text
, can receive the delete and download notifications.
notification_files_preview_text="${notification_files_preview_text//$'\n'/'<br/>'}"
wecom_text="$(echo -e "<font style="line-height:1.5"><center><b><big><big>同步日志</big></big></b></font></center><center><b>${notification_message}</b></center><center>··················· <small>最近 ${notification_files_preview_count} 条${notification_files_preview_type}记录如下</small> ····················</center><code><small>${notification_files_preview_text}</small></code><center>··················· <small>下次同步时间为 ${syn_next_time}</small> ··················</center>")"
However, when I put the notification_files_preview_text
variable directly into wecom_text
and then convert it, I can only receive the download notification, can not receive the delete notification.
wecom_text="$(echo -e "<font style="line-height:1.5"><center><b><big><big>同步日志</big></big></b></font></center><center><b>${notification_message}</b></center><center>··················· <small>最近 ${notification_files_preview_count} 条${notification_files_preview_type}记录如下</small> ····················</center><code><small>${notification_files_preview_text//$'\n'/'<br/>'}</small></code><center>··················· <small>下次同步时间为 ${syn_next_time}</small> ··················</center>")"
Hi,
I've made those changes and pushed the new version to Dockerhub.
Thanks.
Nice, Thanks a lot.
Found a bug, can you help fix it?
The validity period of wecom_token is two hours, wecom_token expired and not updated.
so when I set the synchronization once every 12 hours, the second synchronization cannot be pushed successfully, becaouse access_token expired.
But the log still shows WeCom deleted files notification sent successfully
2022-07-23T07:24:53.345541355Z 2022-07-23 15:24:53 INFO Number of files deleted: 10
2022-07-23T07:24:53.350306586Z 2022-07-23 15:24:53 INFO Sending WeCom deleted files notification
2022-07-23T07:24:53.354601917Z 2022-07-23 15:24:53 INFO wecom_text: <font style=line-height:1.5><center><b><big><big>同步日志</big></big></b></font></center><center><b>iCloud 图库同步完成,删除 10 张照片</b></center><center>··················· <small>最近 10 条删除记录如下</small> ····················</center><code><small>2022-07-02/IMG_1278.HEIC<br/>2022-07-09/IMG_1304.PNG<br/>2022-07-07/IMG_1296.PNG<br/>2022-07-09/IMG_1300.PNG<br/>2022-07-09/RPReplay_Final1657360848.mp4<br/>2022-07-09/IMG_1301.PNG<br/>2022-07-09/IMG_1307.PNG<br/>2022-07-09/IMG_1302.PNG<br/>2022-07-09/IMG_1303.PNG<br/>2022-07-10/IMG_1308.MOV</small></code><center>··················· <small>下次同步时间为 21:24:53</small> ··················</center>
2022-07-23T07:24:53.772694918Z 2022-07-23 15:24:53 ERROR {"errcode":42001,"errmsg":"access_token expired, hint: [], more info at https://open.work.weixin.qq.com/devtool/query?e=42001"}
2022-07-23T07:24:53.772694918Z 2022-07-23 15:24:53 INFO WeCom deleted files notification sent successfully
The test debug code I added is like this
####### debug
LogInfo "wecom_text: ${wecom_text}"
curl --data-ascii "{\"touser\":\"${touser}\",\"msgtype\":\"mpnews\",\"agentid\":\"${agentid}\",\"mpnews\":{\"articles\":[{\"title\":\"${notification_title} 照片同步 - ${name}\",\"thumb_media_id\":\"${thumb_media_id}\",\"author\":\"${syn_end_time}\",\"content_source_url\":\"${content_source_url}\",\"content\":\"${wecom_text}\",\"digest\":\"${notification_message}\"}]},\"safe\":\"0\",\"enable_id_trans\":\"0\",\"enable_duplicate_check\":\"0\",\"duplicate_check_interval\":\"1800\"}" --url "${notification_url}"
notification_result="$(curl --silent --output /dev/null --write-out "%{http_code}" --data-ascii "{\"touser\":\"${touser}\",\"msgtype\":\"mpnews\",\"agentid\":\"${agentid}\",\"mpnews\":{\"articles\":[{\"title\":\"${notification_title} 照片同步 - ${name}\",\"thumb_media_id\":\"${thumb_media_id}\",\"author\":\"${syn_end_time}\",\"content_source_url\":\"${content_source_url}\",\"content\":\"${wecom_text}\",\"digest\":\"${notification_message}\"}]},\"safe\":\"0\",\"enable_id_trans\":\"0\",\"enable_duplicate_check\":\"0\",\"duplicate_check_interval\":\"1800\"}" --url "${notification_url}")"
####### debug
Hi,
That should be it fixed. During initialisation, I now set a web_token_expiry variable two hours in the future.
wecom_token_url="https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$wecom_id}&corpsecret={$wecom_secret}"
wecom_token="$(/usr/bin/curl -s -G "${wecom_token_url}" | awk -F\" '{print $10}')"
wecom_token_expiry="$(date --date='2 hour')"
notification_url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${wecom_token}"
LogInfo "${notification_type} notifications enabled"
LogInfo "${notification_type} token: ${wecom_token}"
LogInfo "${notification_type} token expiry time: $(date -d "${wecom_token_expiry}")"
LogInfo "${notification_type} notification URL: ${notification_url}"
Then when sending the notification, I check if the current time is greater than or equal to the time that was two hours in the future. If it is, I delete the variable:
if [ "$(date +'%s')" -ge "$(date +'%s' -d "${wecom_token_expiry}")" ]; then
unset wecom_token
fi
Then, if the variable does not exist, I generate a new one, and set the expiry date to two hours in the future:
if [ -z "${wecom_token}" ]; then
LogWarning "${notification_type} token has expired. Retrieving new one"
wecom_token="$(/usr/bin/curl -s -G "${wecom_token_url}" | awk -F\" '{print $10}')"
wecom_token_expiry="$(date --date='2 hour')"
notification_url="https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=${wecom_token}"
LogInfo "${notification_type} token: ${wecom_token}"
LogInfo "${notification_type} token expiry time: $(date -d "${wecom_token_expiry}")"
LogInfo "${notification_type} notification URL: ${notification_url}"
fi
Can you pull the latest container from Dockerhub and let me know if you have any further issues?
Thanks.
thank you very much for your help.
I have updated the latest mirror and will feedback.
After a few days of test, wecom notification has worked fine. Thanks!
Great news. I will close this issue.
Thanks.