Why the telegram bot doesn`t recognize the url while the hashtag '#' is at the first of the message? - telegram-bot

I have a telegram bot by PHP which removes messages which contain url, but when the the user send the hashtag # at the first of the message it doesn't remove the url !
$input=file_get_contents("php://input");
$update=json_decode($input,true);
$entity_type=$update['message']['entities'][0]['type'];
$chat_id=$update['message']['chat']['id'];
$message_id=$update['message']['message_id'];
if ($entity_type=='url' ){
bot("deleteMessage?chat_id=".$chat_id."&message_id=".$msg_id);
}
forexample it removes www.google.com but doesn't remove
#info
www.google.com
Why it doesn't recognize the url ? Is there any clue ?

A message containing "#info www.google.com" has two entities.
You need to check if any of them is of type url.
Your code is checking only the first entity. (Which is of type hashtag and not url).

Related

Getting the main url on which error occured in Yii 1

We have implemented an error handler for Yii 1. Also we have implemented the mail functionality with this as any error occurred an email will be send to us but the problem is we are not getting the current URL on which error is generating. Like one page controller/action can contain many images favicons etc. So if any image is missing then we are getting the image URL which showing 404 from:
$url = Yii::app()->createAbsoluteUrl(Yii::app()->request->url);
But we are not getting current URL not even in $error = Yii::app()->errorHandler->error.
So we are not getting the page in which image is absent. Please let me know if is there any way to get current page URL as I have tried many ways but all they are returning the missing images URL instead of main page URL for which images are missing.
createAbsoluteUrl() expects route as first argument - it may return random results if you provide URL instead of route (like in your code snippet).
If you want absolute URL of current request, you may use combination of getUrl() and getHostInfo():
$url = Yii::app()->request->getHostInfo() . Yii::app()->request->getUrl();
In case of error you can get current page url using Yii::app()->request->requestUri in Yii 1.

What does Mandrill status = "invalid" mean in Send Message API response

Mandrill official documentation says that the status property in the response of Send Message API request is:
the sending status of the recipient - either "sent", "queued", "scheduled", "rejected", or "invalid"
Can't find anywhere what does invalid status indicate.
Any idea, referece ?
One reason I have found is an invalid email address. For example having two dots in a domain like this: alice#example..com
I had this happen because some of the properties in the JSON I posted had uppercase letters when the mandrill api was expecting lowercase.
I was using newtonsoft and solved it by adding JsonProperty attributes to my objects as described here: https://stackoverflow.com/a/34071205

Crawler4J seed url gets encoded and error page is crawler instead of actual page

I am using crawler 4J to crawl user profile on gitHub for instance I want to crawl url: https://github.com/search?q=java+location:India&p=1
for now I am adding this hard coded url in my crawler controller like:
String url = "https://github.com/search?q=java+location:India&p=1"; controller.addSeed(url);
When crawler 4J starts the URL Crawled is :
https://github.com/search?q=java%2Blocation%3AIndia&p=1
which gives me error page.
What should I do, I have tried giving encoded url but that doesn't work either.
I had to eventually make the slightest of changes to crawler4J source code:
File Name: URLCanonicalizer.java
Method : percentEncodeRfc3986
Just commented the first line in this method and I was able to crawl and fetch my results
//string = string.replace("+", "%2B");
In my url there was + character and that was being replaced by %2B and I was getting a error page,I wonder why they have specifically replaced + character before encoding the entire URL.

Use URL as an API method for Slackbot in Express js

I am still new to javascript and trying to write a Slackbot in express js. I want to use the method defined in https://api.slack.com/methods/channels.history. How should this look syntacticly and how do I use it since the method is simply a URL?
You need to make an http request for the URL and you'll be returned a response with an object containing the status (ok:true|false), if there are more messages (has_more:true|false), and then an array of the actual messages (messages:array).
The response should look something like this:
{
has_more:true
messages:Array[100]
ok:true
}
The url that you make the get request to should look something like:
https://slack.com/api/channels.history?token=BOT_TOKEN&channel=CHANNEL_ID&pretty=1
Where BOT_TOKEN is the token attached to the bot you created, and CHANNEL_ID is the ID (not the name) of the channel whos history you want to get (9 uppercase alphanumeric characters, starts with a "C").
There are also a few other parameters you can include in the url. For example, "latest=", "oldest=", "inclusive=", "count=", and "unreads=". Details about those parameters can be found on the page you linked to (https://api.slack.com/methods/channels.history).
If you want to test it out in your browser's console, find a page where jQuery is loaded, open your dev tools and head into the console, and enter the following (with your bot token and channel id swapped in):
$.get('https://slack.com/api/channels.history?token=BOT_TOKEN&channel=CHANNEL_ID&pretty=1', function(response){console.log(response)});

Send multiple values for one form param in clj-http?

(defn do-request [url query-map]
"Executes HTTP client"
(client/post url {:form-params query-map}))
(do-request "http://foo.com/api" {:a [val1 val2 val3]})
I need to send multiple values for a single key. The API docs state that I need to pass them like foo.com/api?a=val1&a=val2&a=val3 but when I pass that through clj-http as above it only does foo.com/api?a=val3.
(For more detail, I'm using Authorize.Net's version 3.1 CSV-based API and trying to add x_line_item which is defined to work as above.)
Actually #dAni was correct. Passing a vector as above works correctly. The debugging endpoint output from Authorize.Net only shows the last entry, but if you set the client email to one you control you will see the line items you send listed.