kanal-interfaces-telegram 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 214fdfb6f4940364c3169b9db39c19276bb9c435ac0204f81b7a2943fb90b1ed
         | 
| 4 | 
            +
              data.tar.gz: 97f7f66f82039c0722ba552a8929739a04fa2b8f6e78a8142a6ec44bdbd4babe
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 8257d35fc51f48850dcf32707c92b25449470c121c28096178a19433cb62f33f2c89fd6f3dbea9934542de2d23d033ef12c6a4a8e44d9573cf68da3264bd8e34
         | 
| 7 | 
            +
              data.tar.gz: 134c37797653dec0f74baa42e7e6db3a2ffbc238451bd55d607e74f9cc992f9a8ed0e5b71711bbaa1725980ea2ea55c38a8698ee59dd08b44b839e9eeea5a1e8
         | 
    
        data/CHANGELOG.md
    CHANGED
    
    | @@ -1,5 +1,11 @@ | |
| 1 1 | 
             
            ## [Unreleased]
         | 
| 2 2 |  | 
| 3 | 
            +
            ## [0.2.0] - 2023-01-30
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            - Library now can send images via .tg_image_path
         | 
| 6 | 
            +
            - Populating separate field in input
         | 
| 7 | 
            +
            - Using output.tg_chat_id and not the one inside interface, this is preparations for future sending outputs in separate methods... Probably
         | 
| 8 | 
            +
             | 
| 3 9 | 
             
            ## [0.1.0] - 2022-11-21
         | 
| 4 10 |  | 
| 5 11 | 
             
            - Initial release
         | 
    
        data/Gemfile.lock
    CHANGED
    
    
| @@ -17,8 +17,16 @@ module Kanal | |
| 17 17 |  | 
| 18 18 | 
             
                      def register_parameters(core)
         | 
| 19 19 | 
             
                        core.register_input_parameter :tg_message, readonly: true
         | 
| 20 | 
            +
                        core.register_input_parameter :tg_text, readonly: true
         | 
| 21 | 
            +
                        core.register_input_parameter :tg_chat_id, readonly: true
         | 
| 22 | 
            +
                        core.register_input_parameter :tg_username, readonly: true
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                        core.register_output_parameter :tg_chat_id
         | 
| 20 25 | 
             
                        core.register_output_parameter :tg_text
         | 
| 21 26 | 
             
                        core.register_output_parameter :tg_reply_markup
         | 
| 27 | 
            +
                        core.register_output_parameter :tg_image_path
         | 
| 28 | 
            +
                        core.register_output_parameter :tg_audio_path
         | 
| 29 | 
            +
                        core.register_output_parameter :tg_document_path
         | 
| 22 30 | 
             
                      end
         | 
| 23 31 |  | 
| 24 32 | 
             
                      def register_hooks(core)
         | 
| @@ -27,11 +35,12 @@ module Kanal | |
| 27 35 | 
             
                        end
         | 
| 28 36 |  | 
| 29 37 | 
             
                        core.hooks.attach :input_before_router do |input|
         | 
| 30 | 
            -
                          input.body = input. | 
| 38 | 
            +
                          input.body = input.tg_text
         | 
| 31 39 | 
             
                        end
         | 
| 32 40 |  | 
| 33 41 | 
             
                        core.hooks.attach :output_before_returned do |input, output|
         | 
| 34 42 | 
             
                          output.tg_text = output.body
         | 
| 43 | 
            +
                          output.tg_chat_id = input.tg_chat_id
         | 
| 35 44 | 
             
                        end
         | 
| 36 45 | 
             
                      end
         | 
| 37 46 | 
             
                    end
         | 
| @@ -26,16 +26,50 @@ module Kanal | |
| 26 26 | 
             
                          input = @core.create_input
         | 
| 27 27 |  | 
| 28 28 | 
             
                          input.tg_message = message
         | 
| 29 | 
            +
                          input.tg_text = message.text
         | 
| 30 | 
            +
                          input.tg_chat_id = message.chat.id
         | 
| 31 | 
            +
                          input.tg_username = message.try(:chat).try(:username) || input.tg_message.try(:from).try(:username)
         | 
| 29 32 |  | 
| 30 33 | 
             
                          output = router.create_output_for_input input
         | 
| 31 34 |  | 
| 32 35 | 
             
                          bot.api.send_message(
         | 
| 33 | 
            -
                            chat_id:  | 
| 36 | 
            +
                            chat_id: output.tg_chat_id,
         | 
| 34 37 | 
             
                            text: output.tg_text,
         | 
| 35 38 | 
             
                            reply_markup: output.tg_reply_markup
         | 
| 36 39 | 
             
                          )
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                          image_path = output.tg_image_path
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                          if image_path && File.exist?(image_path)
         | 
| 44 | 
            +
                            bot.api.send_photo(
         | 
| 45 | 
            +
                              chat_id: message.chat.id,
         | 
| 46 | 
            +
                              photo: Faraday::UploadIO.new(image_path, guess_mimetype(image_path))
         | 
| 47 | 
            +
                            )
         | 
| 48 | 
            +
                          end
         | 
| 49 | 
            +
                        end
         | 
| 50 | 
            +
                      end
         | 
| 51 | 
            +
                    end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                    private
         | 
| 54 | 
            +
             | 
| 55 | 
            +
                    def guess_mimetype(filename)
         | 
| 56 | 
            +
                      images = {
         | 
| 57 | 
            +
                        "image/jpeg" => %w[jpg jpeg],
         | 
| 58 | 
            +
                        "image/png" => ["png"],
         | 
| 59 | 
            +
                        "image/bmp" => ["bmp"]
         | 
| 60 | 
            +
                      }
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                      # TODO: rewrite with .find or .each
         | 
| 63 | 
            +
                      for pack in [images] do
         | 
| 64 | 
            +
                        for mime, types in pack do
         | 
| 65 | 
            +
                          for type in types do
         | 
| 66 | 
            +
                            return mime if filename.include? type
         | 
| 67 | 
            +
                          end
         | 
| 37 68 | 
             
                        end
         | 
| 38 69 | 
             
                      end
         | 
| 70 | 
            +
             | 
| 71 | 
            +
             | 
| 72 | 
            +
                      "application/octet-stream"
         | 
| 39 73 | 
             
                    end
         | 
| 40 74 | 
             
                  end
         | 
| 41 75 | 
             
                end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: kanal-interfaces-telegram
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.1 | 
| 4 | 
            +
              version: 0.2.1
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - idchlife
         | 
| @@ -47,7 +47,6 @@ files: | |
| 47 47 | 
             
            - lib/kanal/interfaces/telegram/plugins/telegram_integration_plugin.rb
         | 
| 48 48 | 
             
            - lib/kanal/interfaces/telegram/telegram_interface.rb
         | 
| 49 49 | 
             
            - lib/kanal/interfaces/telegram/version.rb
         | 
| 50 | 
            -
            - pep.rb
         | 
| 51 50 | 
             
            - sig/kanal/interfaces/telegram.rbs
         | 
| 52 51 | 
             
            homepage: https://github.com/idchlife/kanal-interfaces-telegram
         | 
| 53 52 | 
             
            licenses:
         |