I am trying to code the telegram bot in ruby, to recognize new_chat_members, as well as responding to commands, at the moment the bot works fine it just does not recognize new members and instead responds with the else command.
Does anyone have any solutions or a work around?
require 'telegram_bot'
bot = TelegramBot.new(token: 'token api')
bot.get_updates(fail_silently: true) do |message|
puts "##{message.from.username}: #{message.text}"
command = message.get_command_for(bot)
message.reply do |reply|
case command
when /start/i
reply.text = "Hi Try /help for command list."
when /help/i
reply.text = "A list of commands that you can use.
/greet - greets new users.
/website - Provides a link to the Connect Platform.
/price - Displays current price.
/supply - Total circulating supply."
when /greet/i
reply.text = "Hello, #{message.from.first_name}. 🤖 Welcome to Connect
telegram, If you need any /help just ask."
when /website/i
reply.text = "welcome, #{message.from.first_name} to the Connect
Platform."
when /price/i
reply.text = "Current price of
when /supply/i
reply.text = "Circulating supply.
when /hi/i
reply.text = "Hi, #{message.from.first_name} Welcome to Connect
telegram, If you need any /help just ask."
if
reply.text = "Hi, #{message.from.new_chat_member}Welcome to the
connect telegram channel"
end
else
reply.text = "Hi, #{message.from.first_name} I do not know what #
{command.inspect} means, try /help for command list"
end
puts "sending #{reply.text.inspect} to ##{message.from.username}"
reply.send_with(bot)
end
end
Related
So i got my bot sending a message using a variable which is: local text1 = message:reply("Text"),
but cannot seem find some answers of how to edit the message variable. i even tried using text1:edit("New Text") and doesn't seem to work, Anyone with experience of Discordia mind help if you know how to make a bot edit it's own message? Here's my bot code:
local discordia = require('discordia')
local client = discordia.Client()
local token = "BOT TOKEN"
client:on('messageCreate', function(message)
if message.content == "hello" then
local text1 = message:reply("Text")
text1:edit("This message has been editted!")
end
client:run("Bot "..token)
According to the source code
text1:setContent("This message has been edited!")
or
text1:update{content = "This message has been edited!"}
should work.
According to the wiki and the Discordia;
for updating the content of your message object 'text1' should be
text1:setContent("This is a new content")
To learn more about it, please check https://github.com/SinisterRectus/Discordia/wiki
Hello i'm trying to send SMS with Twilio and Ruby.
Everything worked fine until today when i'm trying to send sms with the error :
Unable to create record: The 'From' number +15005550006 is not a valid phone number, shortcode, or alphanumeric sender ID.
Here is my code, i don't understand why it is not working. For informations, i'm using my test credentials.
def boot_twilio
#twilio_number = ENV['TWILIO_NUMBER']
account_sid = ENV['TWILIO_ACCOUNT_SID']
auth_token = ENV['TWILIO_AUTH_TOKEN']
#client = Twilio::REST::Client.new(account_sid, auth_token)
end
def notification(user)
boot_twilio
#client.messages.create(
from: #twilio_number,
to: user.phone
body: "test"
)
end
Thank you in advance !
Please check again your credentials, and maybe your bills too at twilio console.
In order to send a test sms using the Twilio test numbers, you need to make sure you are using your test credentials. From the looks of this code it seems you may be using your actual credentials.
from: https://github.com/twilio/twilio-node/issues/125
I understand the whole process of dialogflow and I have a working deployed bot with 2 different intents. How do I actually get the response from the bot when a user answers questions? (I set the bot on fulfillment to go to my domain). Using rails 5 app and it's deployed with Heroku.
Thanks!
If you have already set the GOOGLE_APPLICATION_CREDENTIALS path to the jso file, now you can test using a ruby script.
Create a ruby file -> ex: chatbot.rb
Write the code bellow in the file.
project_id = "Your Google Cloud project ID"
session_id = "mysession"
texts = ["hello"]
language_code = "en-US"
require "google/cloud/dialogflow"
session_client = Google::Cloud::Dialogflow::Sessions.new
session = session_client.class.session_path project_id, session_id
puts "Session path: #{session}"
texts.each do |text|
query_input = { text: { text: text, language_code: language_code } }
response = session_client.detect_intent session, query_input
query_result = response.query_result
puts "Query text: #{query_result.query_text}"
puts "Intent detected: #{query_result.intent.display_name}"
puts "Intent confidence: #{query_result.intent_detection_confidence}"
puts "Fulfillment text: #{query_result.fulfillment_text}\n"
end
Insert your project_id. You can find this information on your agent on Dialogflow. Click on the gear on the right side of the Agent's name in the left menu.
Run the ruby file in the terminal or in whatever you using to run ruby files. Then you see the bot replying to the "hello" message you have sent.
Obs: Do not forget to install the google-cloud gem:
Not Entirely familiar with Dilogflow, but if you want to receive a response when an action occurs on another app this usually mean you need to receive web-hooks from them
A WebHook is an HTTP callback: an HTTP POST that occurs when something happens; a simple event-notification via HTTP POST. A web application implementing WebHooks will POST a message to a URL when certain things happen.
I would recommend checking their fulfillment documentation for an example. Hope this helps you out.
We have a mail interceptor in our local environment, so that email aren't sent to the actual mail addresses, but a copy is sent to the developpers (devs#project.com).
It is cool, except that all the developpers receive the mails of the whole team, which can be annoying, disturbing.
I'd like to filter with each one using his own email address. I thought of using the git email address, which is set by all of us.
Can my Rails code have an access to this mail address?
Otherwise, I'll create a .gitignored file that each of us should set, but that's more setup then.
Found the solution here: Is it possible to call Git or other command line tools from inside a Thor script?
mail = %x(git config user.email)
So the whole interceptor would be:
class DevelopmentMailInterceptor
def self.delivering_email(message)
git_email = %x(git config user.email)
filter_email = !git_email.empty? git_email : 'devs#project.com'
if Rails.env.development? && !message.to.include?(filter_email)
message.subject = "[Local Filter] To: #{message.to} - #{message.subject}"
message.to = filter_email
end
return message
end
end
I need to get some admin users using google apps gmail the ability to monitor their employees email. Have you used Google's Audit API to do this.
I wish there there was a way for the admins to just click a view my users email but that doesn't be the case.
If it matters the application is a rails app. The email is completely done on googles mail through google apps. Anyone that has done this any advice would be helpful.
Update! 500 points for this one!
I'm using ruby on rails hosting an app on heroku. The email is completely hosted with google apps standard, not business so we will have to upgrade, and the DNS is with zerigo which you already know if you use heroku.
Well, I hadn't planned on extending the gdata-ruby-util gem :), but here's some code that could be used for the Google Audit API based on Google's documentation. I only wrote a create_monitor_on method, but the rest are pretty easy to get.
Let me know if it works or needs any rewrites and I'll update it here:
class Audit < GData::Client::Base
attr_accessor :store_at
def initialize(options = {})
options[:clientlogin_service] ||= 'apps'
options[:authsub_scope] ||= 'https://apps-apis.google.com/a/feeds/compliance/audit/'
super(options)
end
def create_monitor_on(email_address)
user_name, domain_name = email_address.split('#')
entry = <<-EOF
<atom:entry xmlns:atom='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>
<apps:property name='destUserName' value='#{#store_at}'/>
<apps:property name='beginDate' value=''/>
<apps:property name='endDate' value='2019-06-30 23:20'/>
<apps:property name='incomingEmailMonitorLevel' value='FULL_MESSAGE'/>
<apps:property name='outgoingEmailMonitorLevel' value='FULL_MESSAGE'/>
<apps:property name='draftMonitorLevel' value='FULL_MESSAGE'/>
<apps:property name='chatMonitorLevel' value='FULL_MESSAGE'/>
</atom:entry>
EOF
return true if post('https://apps-apis.google.com/a/feeds/compliance/audit/mail/monitor/'+domain_name+'/'+user_name, entry).status_code == 201
false
end
end
Then use it elsewhere like this:
auditor = Audit.new
auditor.store_at = 'this-username'
auditor.clientlogin(username, password)
render :success if auditor.create_monitor_on('email-address#my-domain.com')
My suggestion is to create one core email address that all the email monitors are sent to, so your admins' inboxes aren't slammed with everyone else's mail. Then in your Rails app, use Net::IMAP to download the messages you want from that master email account. i.e., you can create a link that says "View Joe's Email" and the method does something like this:
require 'net/imap'
imap = Net::IMAP.new('imap.gmail.com', 993, true)
imap.login('this-username#my-domain.com', password)
imap.select('INBOX')
messages = []
imap.search(["TO", "joe#email.com").each do |msg_id|
msg = imap.fetch(msg_id, "(UID RFC822.SIZE ENVELOPE BODY[TEXT])")[0]
body = msg.attr["BODY[TEXT]"]
env = imap.fetch(msg_id, "ENVELOPE")[0].attr["ENVELOPE"]
messages << {:subject => env.subject, :from => env.from[0].name, :body => body }
end
imap.logout
imap.disconnect
Then you can put those messages in your view -- or send them all in one bulk email, or whatever you want to do.