#!/usr/bin/bash

# 0 9 * * 4 source /etc/profile && /usr/bin/bash /home/ssm-user/timer.sh

urlFin="s3://prod-devtier-billing/prod-devtier-daily-billing-finance.csv"
urlDetail="s3://prod-devtier-billing/prod-devtier-daily-billing-detail.csv"
urlTenant="s3://prod-devtier-billing/max/tenant_info_active_2022-07.csv"

resFin="$(AWS_REGION=us-west-2 /usr/local/bin/aws s3 presign $urlFin --expires-in 604800)"
echo $resFin
resDetail="$(AWS_REGION=us-west-2 /usr/local/bin/aws s3 presign $urlDetail --expires-in 604800)"
echo $resDetail
#resTenant="$(AWS_REGION=us-west-2 /usr/local/bin/aws s3 presign $urlTenant --expires-in 604800)"
#echo $resFin

body='{"msg_type":"post","content":{"post":{"zh_cn":{"title":"账单地址更新（7日内有效）","content":[[{"tag":"text","text":"每日账单-财务版:"},{"tag":"a","text":"请下载('$urlFin')","href":"'$resFin'"}]]}}}}'
bodyDetail='{"msg_type":"post","content":{"post":{"zh_cn":{"title":"账单地址更新（7日内有效）","content":[[{"tag":"text","text":"每日账单-明细版:"},{"tag":"a","text":"请下载('$urlDetail')","href":"'$resDetail'"}]]}}}}'
echo $body


## finance webhook
res=$(curl -H "Content-Type: application/json"  -X POST -d "$body" https://open.feishu.cn/open-apis/bot/v2/hook/acf6373e-b550-41ca-be70-ef76473b8052)

## team webhook
res=$(curl -H "Content-Type: application/json"  -X POST -d "$body" https://open.feishu.cn/open-apis/bot/v2/hook/f3a838e2-1a9a-40cf-a3c6-a10c88e29a3f)
echo $res
res=$(curl -H "Content-Type: application/json"  -X POST -d "$bodyDetail" https://open.feishu.cn/open-apis/bot/v2/hook/f3a838e2-1a9a-40cf-a3c6-a10c88e29a3f)
echo $res
