Skip to content

Commit

Permalink
feat: send document
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaddeusJiang committed Jul 19, 2024
1 parent 7969aad commit b8a9154
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
2 changes: 2 additions & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ import Config
config :aier_bot, :telegram_bot_token, System.fetch_env!("TELEGRAM_BOT_TOKEN")
config :aier_bot, :aier_api_token, System.fetch_env!("AIER_API_TOKEN")
config :aier_bot, :openai_api_key, System.fetch_env!("OPENAI_API_KEY")

config :ex_gram, token: System.fetch_env!("TELEGRAM_BOT_TOKEN")
9 changes: 5 additions & 4 deletions lib/aier_bot/bot.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ defmodule AierBot.Bot do
end
end

def handle({:text, text, _msg}, context) do
def handle({:text, text, %{chat: chat}}, context) do
# TODO: repeat
# request download API
data = CobaltClient.json(text)
file_content = CobaltClient.json(text)

IO.inspect(data)
{:ok, message} = ExGram.send_document(chat.id, {:file_content, file_content, "video.mp4"})
IO.inspect(message)

answer(context, "#{data}")
answer(context, "done")
# case AierApi.create_memo(text) do
# {:ok, response} -> create_memo_success(response, context)
# {:error, error} -> answer(context, "Error: #{inspect(error)}")
Expand Down
6 changes: 4 additions & 2 deletions lib/aier_bot/cobalt_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ defmodule AierBot.CobaltClient do
# "url" => "https://video.twimg.com/amplify_video/1814202798097268736/vid/avc1/720x1192/HAD9zyJn1xoP4oRN.mp4?tag=16"
# }
%{"url" => url} = response.body
FileDownloader.download(url, "video.mp4")
url
file_content = FileDownloader.download(url, "video.mp4")
file_content

# TODO send photo to telegram

{:error, error} ->
error
Expand Down
1 change: 1 addition & 0 deletions lib/aier_bot/file_downloader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule AierBot.FileDownloader do
{:ok, %Tesla.Env{status: 200, body: body}} ->
File.write("./downloads/#{file_path}", body)
IO.puts("File downloaded successfully.")
body

{:ok, %Tesla.Env{status: status}} ->
IO.puts("Failed to download file. Status: #{status}")
Expand Down

0 comments on commit b8a9154

Please sign in to comment.