首页 > 解决方案 > 如何将红宝石中的电报机器人上传到heroku

问题描述

我无法将用 ruby​​ 制作的简单电报机器人部署到 heroku,而且我找不到任何使其工作的文档或示例。我只有4个文件:

档案

worker: bundle exec ruby src/bot.rb

宝石文件

source 'https://rubygems.org'

ruby '2.6.3'
gem 'telegram_bot'

Gemfile.lock,当我运行“捆绑安装”时生成

src/bot.rb

require 'telegram_bot'

token = ENV['BOT_TOKEN']

bot = TelegramBot.new(token: token)

bot.get_updates(fail_silently: true) do |message|
  #do some stuff
end

当我运行 git push heroku main 时,出现以下错误:

remote: Building source:
remote:
remote: -----> Building on the Heroku-20 stack
remote: -----> Determining which buildpack to use for this app
remote:  !     No default language could be detected for this app.
remote:             HINT: This occurs when Heroku cannot detect the buildpack to use for this application automatically.
remote:             See https://devcenter.heroku.com/articles/buildpacks
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !   Push rejected to my-bot.
remote:
To https://git.heroku.com/my-bot.git

如果我手动添加 buildpack,它说不兼容,没有检测到这是一个 ruby​​ 项目。例如,如果我添加一个 package.json 文件,它会部署 OK,将其标识为 nodejs,而当我运行它时,它会失败,因为未识别 require。

我究竟做错了什么?

标签: rubyherokutelegram-bot

解决方案


推荐阅读