taipeion-api: Library for TaipeiON message API

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

Please see the README on GitHub at https://github.com/h-alice/taipeion-message-api#readme


[Skip to Readme]

Properties

Versions 0.1.0.0
Change log CHANGELOG.md
Dependencies aeson (>=2.1.2 && <2.3), base (>=4.7 && <5), base64-bytestring (>=1.2.1 && <1.3), bytestring (>=0.11.5 && <0.12), containers (>=0.6.7 && <0.7), hspec (>=2.11.12 && <2.12), http-client (>=0.7.19 && <0.8), http-conduit (>=2.3.9 && <2.4), http-types (>=0.12.4 && <0.13), raw-strings-qq (>=1.1 && <1.2), text (>=2.0.2 && <2.1) [details]
License BSD-3-Clause
Copyright 2025 Wayne Hong (h-alice)
Author h-alice
Maintainer admin@halice.art
Category Api
Home page https://github.com/h-alice/taipeion-message-api#readme
Bug tracker https://github.com/h-alice/taipeion-message-api/issues
Source repo head: git clone https://github.com/h-alice/taipeion-message-api
Uploaded by h_alice at 2025-09-16T01:11:10Z

Modules

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for taipeion-api-0.1.0.0

[back to package description]

taipeion-api

A Haskell client library for interacting with the TaipeiON Message API.

This library provides a strongly-typed interface for sending messages, uploading/downloading files, and parser for incoming webhook events, with clean functional pattern and user friendly design.

Usage

Message API

Client Initialization

To inteact with TaipeiON API, first define your channel credentials and the API endpoint.

import TaipeiOn.Client
import TaipeiOn.Message
import TaipeiOn.Response
import Data.Text (Text)

-- Replace with your channel credentials
myChannel :: Channel
myChannel = Channel
  { chanId = 12345
  , chanToken = "CHANNEL_ACCESS_TOKEN"
  , chanSecret = "CHANNEL_SECRET"
  , chanApiToken = "API_PLATFORM_SUBSCRIPTION_KEY"
  }

-- The TaipeiON API endpoint
apiEndpoint :: String
apiEndpoint = "https://myapi.gov.taipei/m-taipeion/MessageFeedService"

Sending a Message

To send a message, construct a MessageObject, wrap it in an Action, and pass it to the tpoClient.

-- Example: Sending a broadcast text message
sendGreeting :: IO ()
sendGreeting = do
  let message = mkTextMessage "Hello from the Haskell client!"
  let action = WriteChannelBroadcast myChannel message

  putStrLn "Sending broadcast message..."
  response <- tpoClient apiEndpoint action

  -- Handle the response
  case response of
    SendMessage smResp ->
      putStrLn $ "Message sent successfully! MessageSN: " ++ show (resMessageSN smResp)
    ErrorResponse errResp ->
      putStrLn $ "API Error: " ++ show (resErrorMessage errResp)
    General genResp ->
      putStrLn $ "Received a generic response with status: " ++ show (resStatusCode genResp)
    _ ->
      putStrLn "Received an unexpected response type."

To send a message to specific user, use action WriteChannelPrivate.

tpoClient endpoint (WriteChannelPrivate myChannel "some-user" message)

taipeion-api implemented not only text messages, but various message types such as image messages, video messages, and more.

Check documentation for more details.

File Upload

To upload a file, you first need to read its contents into a ByteString, then use the UploadFile action.

Check the resFileID field of the parsed response to get the file id, which is needed to send a media message.

-- Example: Uploading a local image
uploadMyImage :: IO ()
uploadMyImage = do
  fileData <- BL.readFile "chiikawa.jpg"
  -- Filename, Extension, Data, IsAsset
  let action = UploadFile myChannel "chiikawa" "jpg" fileData Nothing

  putStrLn "Uploading file..."
  response <- tpoClient apiEndpoint action

  case response of
    UploadFileResponse ufResp -> do
      putStrLn $ "File uploaded successfully! FileID: " ++ unpack (resFileID ufResp)
      -- Now you can use this FileID to send an image message
      let imageMessage = mkImageMessage (Just "ε‰δΌŠε‘ε“‡") "chiikawa.jpg" (resFileID ufResp)
      let sendAction = WriteChannelPrivate myChannel "some-user" imageMessage
      responseMsg <- tpoClient apiEndpoint sendAction
      -- ... response processing ...
    ErrorResponse errResp ->
      putStrLn $ "API Error: " ++ show (resErrorMessage errResp)
    _ ->
      putStrLn "Received an unexpected response type."

Webhook Integration

When your application receives a POST request from a TaipeiON webhook, you can parse the body using the Data.Aeson.decode function with the WebhookPayload type.

API Modules

For detailed information on all available types and functions, please consult the documentation.

Contributing

Check the Development Guide for instructions on how to get started.

License

This project is licensed under the BSD-3-Clause License. See the LICENSE file for details.