From a17856f676771101e63e97a0d5dbc5ac91628a0b Mon Sep 17 00:00:00 2001 From: charconstpointer Date: Tue, 3 Aug 2021 22:26:04 +0200 Subject: [PATCH 1/7] feat(textmagic): add support for textmagic --- go.mod | 2 +- go.sum | 27 +++++++++ service/textmagic/textmagic.go | 102 +++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 service/textmagic/textmagic.go diff --git a/go.mod b/go.mod index a21b124..9b141f4 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/gotify/go-api-client/v2 v2.0.4 github.com/gregdel/pushover v0.0.0-20210216095829-2131362cb888 - github.com/nikoksr/notify v0.17.0 + github.com/nikoksr/notify v0.17.2 github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sfreiberg/gotwilio v0.0.0-20201211181435-c426a3710ab5 github.com/silenceper/wechat/v2 v2.0.6 diff --git a/go.sum b/go.sum index 8be89d2..a414851 100644 --- a/go.sum +++ b/go.sum @@ -48,21 +48,34 @@ github.com/Rhymen/go-whatsapp/examples/sendImage v0.0.0-20190325075644-cc2581bbf github.com/Rhymen/go-whatsapp/examples/sendTextMessages v0.0.0-20190325075644-cc2581bbf24d/go.mod h1:suwzklatySS3Q0+NCxCDh5hYfgXdQUWU1DNcxwAxStM= github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20210506200512-3b3352a919f0 h1:1j26aiGFmsEd43MNlVpXISIqhdo608SlzuUVSCJcwAM= github.com/RocketChat/Rocket.Chat.Go.SDK v0.0.0-20210506200512-3b3352a919f0/go.mod h1:rjP7sIipbZcagro/6TCk6X0ZeFT2eyudH5+fve/cbBA= +github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf h1:eg0MeVzsP1G42dRafH3vf+al2vQIJU0YHX+1Tw87oco= github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY= github.com/atc0005/go-teams-notify/v2 v2.5.0 h1:WKkrbYe2gfT76rltlWTjg8Eukvz0tvzAqs2jyC3pQe0= github.com/atc0005/go-teams-notify/v2 v2.5.0/go.mod h1:BSlh1HBcgWcGoNM3Abm36WMPcj+k8Wf0ZLZx6lBx2qk= +github.com/atc0005/go-teams-notify/v2 v2.6.0 h1:YegKDWbjlatR0fP2yHsQYXzTcUGNJXhm1/OiCgbyysc= +github.com/atc0005/go-teams-notify/v2 v2.6.0/go.mod h1:xo6GejLDHn3tWBA181F8LrllIL0xC1uRsRxq7YNXaaY= github.com/aws/aws-sdk-go-v2 v1.6.0/go.mod h1:tI4KhsR5VkzlUa2DZAdwx7wCAYGwkZZ1H31PYrBFx1w= +github.com/aws/aws-sdk-go-v2 v1.7.0/go.mod h1:tb9wi5s61kTDA5qCkcDbt3KRVV74GGslQkl/DRdX/P4= github.com/aws/aws-sdk-go-v2/config v1.3.0/go.mod h1:lOxzHWDt/k7MMidA/K8DgXL4+ynnZYsDq65Qhs/l3dg= +github.com/aws/aws-sdk-go-v2/config v1.4.1/go.mod h1:HCDWZ/oeY59TPtXslxlbkCqLQBsVu6b09kiG43tdP+I= github.com/aws/aws-sdk-go-v2/credentials v1.2.1/go.mod h1:Rfvim1eZTC9W5s8YJyYYtl1KMk6e8fHv+wMRQGO4Ru0= +github.com/aws/aws-sdk-go-v2/credentials v1.3.0/go.mod h1:tOcv+qDZ0O+6Jk2beMl5JnZX6N0H7O8fw9UsD3bP7GI= github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.1.1/go.mod h1:GTXAhrxHQOj9N+J5tYVjwt+rpRyy/42qLjlgw9pz1a0= +github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.2.0/go.mod h1:XvzoGzuS0kKPzCQtJCC22Xh/mMgVAzfGo/0V+mk/Cu0= github.com/aws/aws-sdk-go-v2/internal/ini v1.0.0/go.mod h1:g3XMXuxvqSMUjnsXXp/960152w0wFS4CXVYgQaSVOHE= +github.com/aws/aws-sdk-go-v2/internal/ini v1.1.0/go.mod h1:qGQ/9IfkZonRNSNLE99/yBJ7EPA/h8jlWEqtJCcaj+Q= github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.1.1/go.mod h1:2+ehJPkdIdl46VCj67Emz/EH2hpebHZtaLdzqg+sWOI= +github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.2.0/go.mod h1:a7XLWNKuVgOxjssEF019IiHPv35k8KHBaWv/wJAfi2A= github.com/aws/aws-sdk-go-v2/service/ses v1.3.1/go.mod h1:6WbvZTnH6a1YzeMZDi/hSjTbPB3RekFw5aQKSwKTksk= +github.com/aws/aws-sdk-go-v2/service/ses v1.4.0/go.mod h1:08bHuVAInVMMxrPBP0iNcWSv+XlN0T1tEjfDUJNKIRk= github.com/aws/aws-sdk-go-v2/service/sso v1.2.1/go.mod h1:VimPFPltQ/920i1X0Sb0VJBROLIHkDg2MNP10D46OGs= +github.com/aws/aws-sdk-go-v2/service/sso v1.3.0/go.mod h1:qWR+TUuvfji9udM79e4CPe87C5+SjMEb2TFXkZaI0Vc= github.com/aws/aws-sdk-go-v2/service/sts v1.4.1/go.mod h1:G9osDWA52WQ38BDcj65VY1cNmcAQXAXTsE8IWH8j81w= +github.com/aws/aws-sdk-go-v2/service/sts v1.5.0/go.mod h1:HjDKUmissf6Mlut+WzG2r35r6LeTKmLEDJ6p9NryzLg= github.com/aws/smithy-go v1.4.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= +github.com/aws/smithy-go v1.5.0/go.mod h1:SObp3lf9smib00L/v3U2eAKG8FyQ7iLrJnQiAmR5n+E= github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0= github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA= github.com/bwmarrin/discordgo v0.23.2 h1:BzrtTktixGHIu9Tt7dEE6diysEF9HWnXeHuoJEt2fH4= @@ -160,6 +173,7 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= @@ -232,6 +246,7 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/line/line-bot-sdk-go v7.8.0+incompatible h1:Uf9/OxV0zCVfqyvwZPH8CrdiHXXmMRa/L91G3btQblQ= github.com/line/line-bot-sdk-go v7.8.0+incompatible/go.mod h1:0RjLjJEAU/3GIcHkC3av6O4jInAbt25nnZVmOFUgDBg= github.com/mailgun/mailgun-go/v4 v4.5.1/go.mod h1:FJlF9rI5cQT+mrwujtJjPMbIVy3Ebor9bKTVsJ0QU40= +github.com/mailgun/mailgun-go/v4 v4.5.2/go.mod h1:FJlF9rI5cQT+mrwujtJjPMbIVy3Ebor9bKTVsJ0QU40= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic= github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ= @@ -249,6 +264,8 @@ github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWb github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nikoksr/notify v0.17.0 h1:Pi5lXgbE8LIEda9mbPJb3GwSCVQL5lbyXkLaj3VvICE= github.com/nikoksr/notify v0.17.0/go.mod h1:INe8kALt/rpdYhYzOuu/pQr3xdVA5Azr1IbiAvSIzPc= +github.com/nikoksr/notify v0.17.2 h1:Aqg+TdITuyeyUvddDUE/u4Mh+eljh4IBP0yZ7g00sXE= +github.com/nikoksr/notify v0.17.2/go.mod h1:yfth7HYk/5vxobRxvN6mD4NMCWX6N/v+43rCurntfdA= github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= @@ -263,6 +280,7 @@ github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/plivo/plivo-go v5.5.2+incompatible/go.mod h1:OhnI9crdl6O+D94Lp1lvuwJoA3KUH39J6IM+j3HwCBE= +github.com/plivo/plivo-go v5.6.0+incompatible/go.mod h1:OhnI9crdl6O+D94Lp1lvuwJoA3KUH39J6IM+j3HwCBE= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= @@ -284,6 +302,8 @@ github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9/go.mod h1:PLPIyL7i github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/slack-go/slack v0.9.1 h1:pekQBs0RmrdAgoqzcMCzUCWSyIkhzUU3F83ExAdZrKo= github.com/slack-go/slack v0.9.1/go.mod h1:wWL//kk0ho+FcQXcBTmEafUI5dz4qz5f4mMk8oIkioQ= +github.com/slack-go/slack v0.9.2 h1:tjIrKKYUCOmWeEAktWShKW+3UjLTH/wmgmCkAGAf8wM= +github.com/slack-go/slack v0.9.2/go.mod h1:wWL//kk0ho+FcQXcBTmEafUI5dz4qz5f4mMk8oIkioQ= github.com/sony/sonyflake v1.0.0 h1:MpU6Ro7tfXwgn2l5eluf9xQvQJDROTBImNCfRXn/YeM= github.com/sony/sonyflake v1.0.0/go.mod h1:Jv3cfhf/UFtolOTTRd3q4Nl6ENqM+KfyZ5PseKfZGF4= github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= @@ -300,7 +320,10 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM= github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog= +github.com/textmagic/textmagic-rest-go-v2/v2 v2.0.1696 h1:TOtsbwwWNeiCCN+EA66/Qr7zXbLSTfmtDeglgC/ZRM8= github.com/textmagic/textmagic-rest-go-v2/v2 v2.0.1696/go.mod h1:PbP69y7uRiNdwtPE3/bVGDaPYA1sr4vuHaGLQAGzeW8= +github.com/textmagic/textmagic-rest-go-v2/v2 v2.0.1781 h1:x7Ff7QDRBy7VDeHNx6/5LsVLJrLc1viDoKwPmEiWF5g= +github.com/textmagic/textmagic-rest-go-v2/v2 v2.0.1781/go.mod h1:PbP69y7uRiNdwtPE3/bVGDaPYA1sr4vuHaGLQAGzeW8= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -389,6 +412,7 @@ golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4Iltr golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= +golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c h1:SgVl/sCtkicsS7psKkje4H9YtjdEl3xsYh7N+5TDHqY= golang.org/x/oauth2 v0.0.0-20210427180440-81ed05c6b58c/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= @@ -494,6 +518,7 @@ golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE= google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M= @@ -516,6 +541,7 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7 google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0= google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= +google.golang.org/appengine v1.6.6 h1:lMO5rYAqUxkmaj76jAkRUvt5JZgFymx/+Q5Mzfivuhc= google.golang.org/appengine v1.6.6/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= @@ -570,6 +596,7 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/service/textmagic/textmagic.go b/service/textmagic/textmagic.go new file mode 100644 index 0000000..e66a45f --- /dev/null +++ b/service/textmagic/textmagic.go @@ -0,0 +1,102 @@ +package textmagic + +import ( + "context" + "fmt" + "strings" + + "github.com/nikoksr/notify" + "github.com/nikoksr/notify/service/textmagic" + "github.com/urfave/cli/v2" +) + +//TextMagic struct describes required data needed to integrate with TextMagic +type TextMagic struct { + Token string + User string + Subject string + Message string + Receivers string +} + +//Send method sends a message via TextMagic service +func Send() *cli.Command { + var textMagicOpts TextMagic + return &cli.Command{ + Name: "textMagic", + Usage: "Send message via TextMagic", + UsageText: "pingme textmagic --token 'tokenabc' --user 'sid123' " + + "--receiver '+140001442' --msg 'some message'", + Description: `textmagic provides ability to send sms to multiple numbers. +You can specify multiple receivers by separating the value with a comma.`, + Flags: []cli.Flag{ + &cli.StringFlag{ + Destination: &textMagicOpts.Token, + Name: "token", + Usage: "TextMagic token", + Aliases: []string{"t"}, + Required: true, + EnvVars: []string{"TEXTMAGIC_TOKEN"}, + }, + &cli.StringFlag{ + Destination: &textMagicOpts.User, + Name: "user", + Usage: "TextMagic user", + Aliases: []string{"u"}, + Required: true, + EnvVars: []string{"TEXTMAGIC_USER"}, + }, + &cli.StringFlag{ + Destination: &textMagicOpts.Subject, + Name: "subject", + Usage: "Subject of the message", + Aliases: []string{"s"}, + Required: true, + EnvVars: []string{"TEXTMAGIC_SUBJECT"}, + }, + &cli.StringFlag{ + Destination: &textMagicOpts.Message, + Name: "receiver", + Usage: "Receiver(s) of the message", + Aliases: []string{"r"}, + Required: true, + EnvVars: []string{"TEXTMAGIC_RECEIVER"}, + }, + &cli.StringFlag{ + Destination: &textMagicOpts.Message, + Name: "msg", + Usage: "Message to send", + Aliases: []string{"m"}, + Required: true, + EnvVars: []string{"TEXTMAGIC_MESSAGE"}, + }, + }, + Action: func(c *cli.Context) error { + textMagicService := textmagic.New(textMagicOpts.User, textMagicOpts.Token) + receivers, err := getReceivers(textMagicOpts.Receivers) + if err != nil { + return fmt.Errorf("invalid receivers provided, %w", err) + } + textMagicService.AddReceivers(receivers...) + + notifier := notify.New() + notifier.UseServices(textMagicService) + + err = notifier.Send(context.Background(), textMagicOpts.Subject, textMagicOpts.Message) + if err != nil { + return fmt.Errorf("could not send textMagic message, %w", err) + } + return nil + }, + } +} + +//getReceivers returns a slice of receivers from comma separated string +//if receivers is an empty string return an error otherwise return slice of strings +func getReceivers(receivers string) ([]string, error) { + if len(receivers) == 0 { + return nil, fmt.Errorf("no receivers found") + } + r := strings.Split(receivers, ",") + return r, nil +} From 628a168de1342753c2e546772156adc92df7e9fb Mon Sep 17 00:00:00 2001 From: charconstpointer Date: Tue, 3 Aug 2021 22:27:07 +0200 Subject: [PATCH 2/7] chore: remove copilot comment --- service/textmagic/textmagic.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/service/textmagic/textmagic.go b/service/textmagic/textmagic.go index e66a45f..0c422be 100644 --- a/service/textmagic/textmagic.go +++ b/service/textmagic/textmagic.go @@ -91,8 +91,6 @@ You can specify multiple receivers by separating the value with a comma.`, } } -//getReceivers returns a slice of receivers from comma separated string -//if receivers is an empty string return an error otherwise return slice of strings func getReceivers(receivers string) ([]string, error) { if len(receivers) == 0 { return nil, fmt.Errorf("no receivers found") From 51a59136f53439ff45cf3effbe0e51e2f4d3dc28 Mon Sep 17 00:00:00 2001 From: charconstpointer Date: Tue, 3 Aug 2021 22:34:59 +0200 Subject: [PATCH 3/7] chore: udpate docs, fix config binding --- docs/services.md | 52 +++++++++++++++++++++++++++++++++- main.go | 2 ++ service/textmagic/textmagic.go | 4 +-- 3 files changed, 55 insertions(+), 3 deletions(-) diff --git a/docs/services.md b/docs/services.md index dfe1772..fb81494 100644 --- a/docs/services.md +++ b/docs/services.md @@ -375,7 +375,7 @@ by comma ',' or you can add permissions for multiple channels to single webhook. pingme teams \ --webhook 'https://example.webhook.office.com/xx' \ --msg 'some message' -``` +``` - GitHub Action @@ -754,3 +754,53 @@ jobs: | WECHAT_RECEIVER_IDS | "" | | WECHAT_MSG_TITLE | "" | | WECHAT_MESSAGE | "" | + +## TextMagic + +TextMagic allows you to send SMS to multiple receivers provided by comma separated string. + +```bash + pingme textmagic \ + --token 'tokenabc' \ + --user 'sid123' \ + --subject '+140001442' \ + --receiver '+140001442' \ + --msg 'some message' +``` + +- GitHub Action + +```yaml +on: [push] + +jobs: + pingme-job: + runs-on: ubuntu-latest + name: PingMe + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Ping me On + uses: kha7iq/pingme-action@v1 + env: + TEAMS_WEBHOOK: ${{ secrets.TEAMS_WEBHOOK }} + TEAMS_MSG_TITLE: 'Reference: ${{ github.ref }}' + TEAMS_MESSAGE: 'Event is triggered by ${{ github.event_name }}' + + with: + # Chose the messaging platform. + # slack / telegram / rocketchat / teams / + # pushover / discord / email / mattermost / textmagic + service: textmagic +``` + +- **Variables** + +| Variables | Default Value | +| -------------------------- | :----------------: | +| TEAMS_USER | "" | +| TEAMS_TOKEN | "" | +| TEAMS_SUBJECT | "" | +| TEAMS_MESSAGE | "" | +| TEAMS_RECEIVER | "" | diff --git a/main.go b/main.go index 9ef4bf8..6efc419 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,7 @@ import ( "os" "github.com/kha7iq/pingme/service/gotify" + "github.com/kha7iq/pingme/service/textmagic" "github.com/kha7iq/pingme/service/mastodon" "github.com/kha7iq/pingme/service/twillio" @@ -56,6 +57,7 @@ email address, Line, Gotify and Wechat.` line.Send(), wechat.Send(), gotify.Send(), + textmagic.Send(), } err := app.Run(os.Args) diff --git a/service/textmagic/textmagic.go b/service/textmagic/textmagic.go index 0c422be..00f0904 100644 --- a/service/textmagic/textmagic.go +++ b/service/textmagic/textmagic.go @@ -23,7 +23,7 @@ type TextMagic struct { func Send() *cli.Command { var textMagicOpts TextMagic return &cli.Command{ - Name: "textMagic", + Name: "textmagic", Usage: "Send message via TextMagic", UsageText: "pingme textmagic --token 'tokenabc' --user 'sid123' " + "--receiver '+140001442' --msg 'some message'", @@ -55,7 +55,7 @@ You can specify multiple receivers by separating the value with a comma.`, EnvVars: []string{"TEXTMAGIC_SUBJECT"}, }, &cli.StringFlag{ - Destination: &textMagicOpts.Message, + Destination: &textMagicOpts.Receivers, Name: "receiver", Usage: "Receiver(s) of the message", Aliases: []string{"r"}, From c5eb07430fe4418aecd8ba7b35696890cb201f6a Mon Sep 17 00:00:00 2001 From: charconstpointer Date: Tue, 3 Aug 2021 22:44:00 +0200 Subject: [PATCH 4/7] add missing subject flag --- service/textmagic/textmagic.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/textmagic/textmagic.go b/service/textmagic/textmagic.go index 00f0904..851eb73 100644 --- a/service/textmagic/textmagic.go +++ b/service/textmagic/textmagic.go @@ -26,7 +26,7 @@ func Send() *cli.Command { Name: "textmagic", Usage: "Send message via TextMagic", UsageText: "pingme textmagic --token 'tokenabc' --user 'sid123' " + - "--receiver '+140001442' --msg 'some message'", + "--subject 'foo' --receiver '+140001442' --msg 'some message'", Description: `textmagic provides ability to send sms to multiple numbers. You can specify multiple receivers by separating the value with a comma.`, Flags: []cli.Flag{ From 2dece090253718bdfb6a82d49cf75ddfcf47b349 Mon Sep 17 00:00:00 2001 From: charconstpointer Date: Wed, 4 Aug 2021 23:03:40 +0200 Subject: [PATCH 5/7] chore: fix services.md --- docs/services.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/services.md b/docs/services.md index fb81494..c312fea 100644 --- a/docs/services.md +++ b/docs/services.md @@ -784,9 +784,11 @@ jobs: - name: Ping me On uses: kha7iq/pingme-action@v1 env: - TEAMS_WEBHOOK: ${{ secrets.TEAMS_WEBHOOK }} - TEAMS_MSG_TITLE: 'Reference: ${{ github.ref }}' - TEAMS_MESSAGE: 'Event is triggered by ${{ github.event_name }}' + TEXTMAGIC_USER: ${{ secrets.TEXTMAGIC_USER }} + TEXTMAGIC_USER: ${{ secrets.TEXTMAGIC_TITLE }} + TEXTMAGIC_MESSAGE: 'Event is triggered by ${{ github.event_name }}' + TEXTMAGIC_TITLE: 'Reference: ${{ github.ref }}' + TEXTMAGIC_RECEIVER: ${{ secrets.TEXTMAGIC_RECEIVER }} with: # Chose the messaging platform. @@ -799,8 +801,8 @@ jobs: | Variables | Default Value | | -------------------------- | :----------------: | -| TEAMS_USER | "" | -| TEAMS_TOKEN | "" | -| TEAMS_SUBJECT | "" | -| TEAMS_MESSAGE | "" | -| TEAMS_RECEIVER | "" | +| TEXTMAGIC_USER | "" | +| TEXTMAGIC_TOKEN | "" | +| TEXTMAGIC_SUBJECT | "" | +| TEXTMAGIC_MESSAGE | "" | +| TEXTMAGIC_RECEIVER | "" | From 53b4fc802779d051c00ec7fa924c1aaf202a8dd2 Mon Sep 17 00:00:00 2001 From: charconstpointer Date: Wed, 4 Aug 2021 23:04:53 +0200 Subject: [PATCH 6/7] chore: fix typo in services.md --- docs/services.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/services.md b/docs/services.md index c312fea..50d22e3 100644 --- a/docs/services.md +++ b/docs/services.md @@ -785,7 +785,7 @@ jobs: uses: kha7iq/pingme-action@v1 env: TEXTMAGIC_USER: ${{ secrets.TEXTMAGIC_USER }} - TEXTMAGIC_USER: ${{ secrets.TEXTMAGIC_TITLE }} + TEXTMAGIC_TOKEN: ${{ secrets.TEXTMAGIC_TOKEN }} TEXTMAGIC_MESSAGE: 'Event is triggered by ${{ github.event_name }}' TEXTMAGIC_TITLE: 'Reference: ${{ github.ref }}' TEXTMAGIC_RECEIVER: ${{ secrets.TEXTMAGIC_RECEIVER }} From 091884f87dba580db68f5d8c916c5110f5fbda98 Mon Sep 17 00:00:00 2001 From: charconstpointer Date: Wed, 4 Aug 2021 23:06:08 +0200 Subject: [PATCH 7/7] chore: consistent naming in textmagic config --- docs/services.md | 2 +- service/textmagic/textmagic.go | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/services.md b/docs/services.md index 50d22e3..3fb9223 100644 --- a/docs/services.md +++ b/docs/services.md @@ -786,8 +786,8 @@ jobs: env: TEXTMAGIC_USER: ${{ secrets.TEXTMAGIC_USER }} TEXTMAGIC_TOKEN: ${{ secrets.TEXTMAGIC_TOKEN }} + TEXTMAGIC_SUBJECT: 'Reference: ${{ github.ref }}' TEXTMAGIC_MESSAGE: 'Event is triggered by ${{ github.event_name }}' - TEXTMAGIC_TITLE: 'Reference: ${{ github.ref }}' TEXTMAGIC_RECEIVER: ${{ secrets.TEXTMAGIC_RECEIVER }} with: diff --git a/service/textmagic/textmagic.go b/service/textmagic/textmagic.go index 851eb73..201e109 100644 --- a/service/textmagic/textmagic.go +++ b/service/textmagic/textmagic.go @@ -12,11 +12,11 @@ import ( //TextMagic struct describes required data needed to integrate with TextMagic type TextMagic struct { - Token string - User string - Subject string - Message string - Receivers string + Token string + User string + Subject string + Message string + Receiver string } //Send method sends a message via TextMagic service @@ -55,7 +55,7 @@ You can specify multiple receivers by separating the value with a comma.`, EnvVars: []string{"TEXTMAGIC_SUBJECT"}, }, &cli.StringFlag{ - Destination: &textMagicOpts.Receivers, + Destination: &textMagicOpts.Receiver, Name: "receiver", Usage: "Receiver(s) of the message", Aliases: []string{"r"}, @@ -73,7 +73,7 @@ You can specify multiple receivers by separating the value with a comma.`, }, Action: func(c *cli.Context) error { textMagicService := textmagic.New(textMagicOpts.User, textMagicOpts.Token) - receivers, err := getReceivers(textMagicOpts.Receivers) + receivers, err := getReceivers(textMagicOpts.Receiver) if err != nil { return fmt.Errorf("invalid receivers provided, %w", err) }