Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actions required due to the end of service for LINE Notify #602

Open
falgon opened this issue Oct 24, 2024 · 0 comments
Open

Actions required due to the end of service for LINE Notify #602

falgon opened this issue Oct 24, 2024 · 0 comments

Comments

@falgon
Copy link
Owner

falgon commented Oct 24, 2024

  • The service for LINE Notify will end at 25/03/31: https://notify-bot.line.me/closing-announce
  • Since line notify is used in certain places, switch to sending bot messages using Line Messaging API.
  • Affected areas:
    • #!/usr/bin/env stack
      -- stack script --resolver lts-14.27 --package bytestring --package case-insensitive --package http-conduit --package utf8-string --package uri-encode --package optparse-applicative
      {-# LANGUAGE OverloadedStrings #-}
      module Main where
      import qualified Data.ByteString as B
      import qualified Data.ByteString.Char8 as BC
      import qualified Data.ByteString.UTF8 as BU
      import qualified Data.CaseInsensitive as CI
      import Data.Functor ((<&>))
      import Network.HTTP.Conduit (RequestBody (..),
      requestHeaders)
      import Network.HTTP.Simple
      import Network.URI.Encode (encodeTextToBS)
      import qualified Options.Applicative as OA
      import qualified Options.Applicative.Help.Pretty as OA
      import System.Environment (getEnv)
      buildBearerAuth :: B.ByteString -> B.ByteString
      buildBearerAuth = B.append "Bearer "
      applyBearerAuth :: B.ByteString -> Request -> Request
      applyBearerAuth bearerToken req = setRequestHeaders (authHeader : requestHeaders req) req
      where
      authHeader = (CI.mk "Authorization", buildBearerAuth bearerToken)
      setRequestBearerAuth :: B.ByteString -> Request -> Request
      setRequestBearerAuth = applyBearerAuth
      lineNotifyAPIEndPoint :: String
      lineNotifyAPIEndPoint = "https://notify-api.line.me/api/notify"
      reqLineNotify :: B.ByteString -> B.ByteString -> Request
      reqLineNotify message token = setRequestMethod "POST"
      $ setRequestBearerAuth token
      $ setRequestQueryString [("message", Just message)]
      $ parseRequest_ lineNotifyAPIEndPoint
      notifyLine :: String -> IO Int
      notifyLine message = getEnv "LINE_NOTIFY_TOKEN"
      >>= httpLbs . reqLineNotify (BU.fromString message) . BC.pack
      <&> getResponseStatusCode
      messageDoc :: String -> String -> OA.Doc
      messageDoc prURL artifactsURL = mconcat [
      OA.line
      , OA.text "🐥 roki-web PR Artifacts 🐥"
      , OA.line
      , OA.line <> OA.text "・PR: " <> OA.text prURL
      , OA.line <> OA.text "・Artifacts: " <> OA.text artifactsURL
      ]
      data Opts = Opts
      { optPRURL :: String
      , optArtifactsURL :: String
      }
      pPRURL :: OA.Parser String
      pPRURL = OA.option OA.str $ mconcat [
      OA.long "pr-url"
      , OA.help "A Pull request URL"
      , OA.metavar "<URL>"
      ]
      pArtifactsURL :: OA.Parser String
      pArtifactsURL = OA.option OA.str $ mconcat [
      OA.long "artifacts-url"
      , OA.help "A Circle CI Artifacts URL"
      , OA.metavar "<URL>"
      ]
      programOptions :: OA.Parser Opts
      programOptions = Opts
      <$> pPRURL
      <*> pArtifactsURL
      optsParser :: OA.ParserInfo Opts
      optsParser = OA.info (OA.helper <*> programOptions) $ mconcat [
      OA.fullDesc
      , OA.progDesc "A script that tells line that the roki-web artifacts build is complete"
      ]
      main :: IO ()
      main = do
      opts <- OA.execParser optsParser
      notifyLine (show $ messageDoc (optPRURL opts) (optArtifactsURL opts))
      >>= print
    • - restore_cache:
      key: v1-notify-line-{{ checksum "tools/circleci/NotifyLine.hs" }}
      - run:
      name: Notify LINE
      command: |
      if << pipeline.parameters.ENABLE_PR_COMMENT >>; then
      if [ -z "$(cat $PR_RESPONSE_TMP)" ]; then
      echo "No PR found to update"
      circleci-agent step halt
      else
      readonly pr_url=$(jq -r ".[]._links.html.href" "$PR_RESPONSE_TMP")
      fi
      else
      readonly pr_url="none"
      fi
      # eval is needed for the CIRCLE_WORKING_DIRECTORY variable as it contains a non-expanded '~'
      eval ${CIRCLE_WORKING_DIRECTORY}/tools/circleci/NotifyLine.hs \
      --pr-url "$pr_url" \
      --artifacts-url "$ARTIFACTS_URL"
      - save_cache:
      key: v1-notify-line-{{ checksum "tools/circleci/NotifyLine.hs" }}
      paths:
      - ~/.stack
    • enable_notify: ${{ steps.enable_notify_step.outputs.flag }}
@falgon falgon self-assigned this Oct 24, 2024
@falgon falgon modified the milestones: Let LINE Bot send a message, Migration of the server running LINE Bot Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant