Compare commits

...
Author SHA1 Message Date
Muhsin Keloth 18a929985b feat: add the support for stickers 2023-12-01 12:46:43 +05:30
+33 -16
View File
@@ -42,25 +42,42 @@ class Line::IncomingMessageService
end end
def attach_files(message) def attach_files(message)
return unless message_type_non_text?(message['type']) return unless message_type_non_text?(message['type']) || message['type'] == 'sticker'
response = inbox.channel.client.get_message_content(message['id']) if message['type'] == 'sticker'
attachment_file = Down.download(
"https://stickershop.line-scdn.net/stickershop/v1/sticker/#{message[:stickerId]}/iphone/sticker.png"
)
file_name = "media-#{message['id']}.#{response.content_type.split('/')[1]}" @message.attachments.new(
temp_file = Tempfile.new(file_name) account_id: @message.account_id,
temp_file.binmode file_type: 'image',
temp_file << response.body file: {
temp_file.rewind io: attachment_file,
filename: "sticker-#{message['stickerId']}.png",
content_type: attachment_file.content_type
}
)
else
response = inbox.channel.client.get_message_content(message['id'])
@message.attachments.new( file_name = "media-#{message['id']}.#{response.content_type.split('/')[1]}"
account_id: @message.account_id, temp_file = Tempfile.new(file_name)
file_type: file_content_type(response), temp_file.binmode
file: { temp_file << response.body
io: temp_file, temp_file.rewind
filename: file_name,
content_type: response.content_type @message.attachments.new(
} account_id: @message.account_id,
) file_type: file_content_type(response),
file: {
io: temp_file,
filename: file_name,
content_type: response.content_type
}
)
end
@message.save! @message.save!
end end