file_get_contents() issues related to my SMS API intrigation - file-get-contents

file_get_contents(http://smshorizon.co.in/api/sendsms.php?user=***&apikey=******&mobile=*****&message=Hello World&senderid=xxyy&type=txt)
Here in this SMS API when I use a message with space say "Hello World" then it return HTTP/1.1 400 Bad Request. But when I remove the space and instead I write HelloWorld it works fine.
What is the issue?

Why its happening (Problem):
URL is getting spitted because of space between messages and it will consider only part before space.
Solution:
You can use PHP inbuilt function urlencode();
Input : urlencode('Hello World');
Output : urlencode('Hello%20World');

Related

Random Error From Node.Js and Lua HTTP Get?

So I'm trying to recieve data like the clients IP from a pipedream workflow using lua(HTTPGET). And so I have a custom body response in Node.JS with no errors. However, when I print the body response in Lua I get this unusual error. It prints the ip but then says A malformed number is near the clients ip.:
My Node.JS code for pipedream:
await $respond({
status: 200,
immediate: true,
body: `${steps.trigger.event.client_ip}`
})
There are no errors, its fine but heres my Lua code to get the response:
function GetServProtocal()
print(loadstring(game:HttpGet('https://enznhjjype22xb2.m.pipedream.net')))()
end
GetServProtocal()
Also, no errors but the output is weird:
-- I'm using 1.1.1.1 example ip for code so I don't expose my real one.
[string "1.1.1.1"]:1: malformed number near "1.1.1.1"
Remove loadstring from your code. The loadstring function expects some Lua code, which it will turn into an executable function and the string that is being returned by HttpGet is not a valid Lua code, hence the error you get.

Adding message to gmail error "Payload parts count different from expected"

I am adding a message to a gmail folder using this (example) URL:
https://www.googleapis.com/gmail/v1/users/user#domain.com/messages/import?uploadType=multipart
The body of the request looks like this:
--test_abc123
Content-Type: application/json; charset=UTF-8
{
"labelIds": [ "Label_525" ],
"raw": "RnJvbTogIlNlY3RpZ28gQ2VydGlmaWNh..."
}
--test_abc123--
The raw data is a base64 encoded standard MIME message that looks normal to me. The result of this POST is http error 400 with the error response "Payload parts count different from expected 2. Request payload parts count: 1".
I can supply the original MIME text if that is helpful, but let me emphasize that I have been running this code for several years without problem. I've tried different messages to test this out, but it appears that Google has changed something to break my software.
Is Google objecting to my raw data, or something about the MIME encoding? Any ideas what the problem could be?
---- Addendum ----
I have gotten a few messages to work, they seem to all have image or data attachments. However I really don't see any problem with the messages that are failing - I can import them into Office 365 or Thunderbird or anything else and they render just fine. As a test, I tried importing the message below, which was taken from the MIME RFC. It fails with the same error. I think that Google has changed something to make their MIME parser very fussy, but I don't see how I can fix my input data.
From: Nathaniel Borenstein <nsb#bellcore.com>
To: Ned Freed <ned#innosoft.com>
Subject: Sample message
MIME-Version: 1.0
Content-type: multipart/mixed; boundary="simple boundary"
This is the preamble. It is to be ignored, though it
is a handy place for mail composers to include an
explanatory note to non-MIME compliant readers.
--simple boundary
This is implicitly typed plain ASCII text.
It does NOT end with a linebreak.
--simple boundary
Content-type: text/plain; charset=us-ascii
This is explicitly typed plain ASCII text.
It DOES end with a linebreak.
--simple boundary--
This is the epilogue. It is also to be ignored.
Addendum 2: I tried a simple upload (using content-type header message/rfc822) and it worked, except the message was unlabeled. How
would I specify what label I want applied to a message? I was originally trying to follow the documentation here
link
which tells me to create the json body that I gave above. This allows me to specify the label. But I cannot seem to use
this body in a simple upload. The content type is either invalid, or what Gmail imports is just literally the json body,
it does not parse out the raw data. If you could point me to a specific example showing the URI, message body, http headers
(not java code) that would be very useful to me.
OK never mind, I got it working by adding an empty message/rfc822 part to the body of the multipart upload. That satisfies Google, and the empty part is ignored in favor of the raw data.
You are doing a multipart upload,see here:
The body of the request is formatted as a multipart/related content
type [RFC2387] and contains exactly two parts. The parts are
identified by a boundary string, and the final boundary string is
followed by two hyphens.
This is why it works only for your messages with images or attachments, since your message
--test_abc123
is only one part.
In the past there was no check if this condition is fulfilled, so you might have gotten away with using multipart for 1-part-messages.
But now it's not possible anymore, so if have a single-part message, you should use Simple upload.
If you do not know in advance how many parts your message has, you can always try the multipart first, implementing a try...catch statement, and implement a simple upload request within catch in case of failure.

DocuSign Get Envelope Status

I am calling https://demo.docusign.net/restapi/v2/accounts/{accountId}/envelopes/status?envelope_ids="{\"envelopeIds\":[\"903780a3-cfc4-4dd8-a7b0-90b10d783dc9\",\"8a579670-03ec-411c-b781-1091df7590ad\"]}" with HTTP PUT in c# with httpwebrequest but getting 400 bad request, please help to fix this one issue.
There are two ways to get status of multiple envelopes:
Using GET Call,
GET
/restapi/v2/accounts/{accountId}/envelopes/status?envelope_ids=39eddd06-0288-4288-91a1-dbe79c732524,
5b54c5dd-4c51-4bc1-8251-6e448de34fd4,8f77680d-90fa-4508-9353-0e0707b9518f
no curly braces in the GET call, just comma separated envelopeIds
Using PUT Call,
PUT /restapi/v2/accounts/{accountId}/envelopes/status?envelope_ids=request_body
Body should be -
{
"envelopeIds":["39eddd06-0288-4288-91a1-dbe79c732524",
"5b54c5dd-4c51-4bc1-8251-6e448de34fd4","8f77680d-90fa-4508-9353- 0e0707b9518f"]
}
PUT call is preferred, because using GET there is a limitation on the number of envelopeIds sent in the URL and you might get an error if you hit that limit, whereas in PUT call all envelopeIds are going in the payload so you will not see any error.

Clear "pending_update_count" in Telegram Bot

I want to clear all pending_update_count in my bot!
The output of below command :
https://api.telegram.org/botxxxxxxxxxxxxxxxx/getWebhookInfo
Obviously I replaced the real API token with xxx
is this :
{
"ok":true,"result":
{
"url":"",
"has_custom_certificate":false,
"pending_update_count":5154
}
}
As you can see, I have 5154 unread updates til now!! ( I'm pretty sure this pending updates are errors! Because no one uses this Bot! It's just a test Bot)
By the way, this pending_update_count number are increasing so fast!
Now that I'm writing this post the number increased 51 and reached to 5205 !
I just want to clear this pending updates.
I'm pretty sure this Bot have been stuck in an infinite loop!
Is there any way to get rid of it?
P.S:
I also cleared the webhook url. But nothing changed!
UPDATE:
The output of getWebhookInfo is this :
{
"ok":true,
"result":{
"url":"https://somewhere.com/telegram/webhook",
"has_custom_certificate":false,
"pending_update_count":23,
"last_error_date":1482910173,
"last_error_message":"Wrong response from the webhook: 500 Internal Server Error",
"max_connections":40
}
}
Why I get Wrong response from the webhook: 500 Internal Server Error ?
I think you have two options:
set webhook that do nothing, just say 200 OK to telegram's servers. Telegram wiil send all updates to this url and the queque will be cleared.
disable webhook and after it get updates by using getUpdates method, after it, turn on webhook again
Update:
Problem with webhook on your side. You can try to emulate telegram's POST query on your URL.
It can be something like this:
{"message_id":1,"from":{"id":1,"first_name":"FirstName","last_name":"LastName","username":"username"},"chat":{"id":1,"first_name":"FirstName","last_name":"LastName","username":"username","type":"private"},"date":1460957457,"text":"test message"}
You can send this text as a POST query body with PostMan for example, and after it try to debug your backend.
For anyone looking at this in 2020 and beyond, the Telegram API now supports clearing the pending messages via a drop_pending_updates parameter in both setWebhook and deleteWebhook, as per the API documentation.
Just add return 1; at the end of your hook method.
Update:
Commonly this happens because of queries delay with the database.
I solved is like this
POST tg.api/bottoken/setWebhook to emtpy "url"
POST tg.api/bottoken/getUpdates
POST tg.api/bottoken/getUpdates with "offset" last update_id appeared before
doing this serveral times
POST tg.api/bottoken/getWebhookInfo
had a look if all away.
POST tg.api/bottoken/setWebhook with filled "url"
If you are using webhook, you can follow these steps
On your web browser, enter the following url with your right value of bot
https://api.telegram.org/bot/getWebhookInf
You will get a result like this on your screen
{"ok":true,"result":{"url":"url_value",...}}
On the displayed result, copy the entire url_value without quotes and replace it on this second url
https://api.telegram.org/bot/setWebhook?url=url_value&drop_pending_updates=True
Enter the second url with right bot and url_value in your web browser then press ENTER
Done!
i solve it by Change file access permissions file - set permissions file to 755
and second increase memory limit in php.ini file
A quick&dirty way is to get a temporary webhook here: https://webhook.site/ and
set your webhook to that (it will answer with a HTTP/200 code everytime, reseting your pending messages to zero)
I faced the same issue for my tele bot after user edited existing message. My bot receives update with editedMessage continuously, but update.hasMessage() was empty. As a result number of updates rocketly increased and my bot stack.
I solved this issue by adding handling for use case when message is missing - send 200 code:
public APIGatewayProxyResponseEvent handleRequest(APIGatewayProxyRequestEvent event, Context context) {
update = MAPPER.readValue(event.getBody(), Update.class);
if (!update.hasMessage()) {
return new APIGatewayProxyResponseEvent()
.withStatusCode(200) // -> !!!!!! return code 200
.withBody("message is missing")
.withIsBase64Encoded(false);
}
... ... ...

Kamailio 4.3.1 Register/200 OK asycnhornous

I am new to Kamailio 4.3.1 and I am trying to use it as described on this http://kb.asipto.com/kamailio:k43-async-sip-routing-nodejs page. Apparently it is a new approach to make asynchronous routing using NodeJS.
I've modified a little bit the example and adapted it with a REGISTER sip and it works quite good. But now I am looking for a way to make the things a little bit more complex.
In the example the NodeJS routine is called only when the REGISTER method has been received. I am trying to make a similar asynchronous call to NodeJS when the '200 OK' comes back from the REGISTERS's destination.
If we have:
Alice---REGISTER(Alice)---> Kamailio (async call to NodeJs)---REGISTER(Alice)-->Asterisk
Later when Asterisk accepts the REGISTER the I want to have this:
Alice<---200 OK---Kamailio(async call to NodeJS)<---200 OK---Asterisk
To catch the 200 OK, I configured Kamailio to execute an async call using EVAPI, like this:
request_route
{
....
route(REGISTRAR);
....
exit;
}
route[REGISTRAR]
{
...
t_on_reply("2OO_OK_RSP"); # Here I tell that I want to catch the "200 OK"
...
exit;
}
# When the 200 OK arrives, this code is called
onreply_route[2OO_OK_RSP]
{
# Here is my async call to NodeJS
evapi_async_relay("send message to NodeJS about 200 OK");
}
#When NodeJS returns
event_route[evapi:message-received]
{
if(200 OK)
{
t_countinue("..", "...", RSP_200OK)
}
}
route[RSP_200OK]
{
t_on_branch("MANAGE_BRANCH");
t_on_failure("MANAGE_FAILURE");
route(RELAY); # I am trying here to relay the 200 OK, which finishes by calling t_relay();
exit;
}
So this is my configuration which is treating the 200 OK. I would like to say that it works (because at the end the 200 Ok is relayed to Alice) BUT Kamailio logs this message:
tm [tm.c:1479]: _w_t_relay_to(): ERROR: w_t_relay_to: unsupported route type: 4
and I don't like this. I know that there is something wrong and when I am looking at the source code of Kamailio it is clear that this is not the right place to treat messages like "200 OK".
My question is, is there any other way (a good way) to relay/route the 200 OK, once the NodeJS has replied? I tried also with
t_reply("200","OK"); instead of t_relay();
But this generates a SIP message "200 OK" which does not contain everything that the messages received by Asterisk. Probably I can tell Kamailio to reply by exactly the same 200 OK, that it has just received?
Thank you in advance!
Best regards,
Anton
So finally I could find how to resolve partially my problem.
I discovered that the module EVAPI proposes a method called evapi_relay() which does not suspend the current transaction but sends a messages to the NodeJS application and relays the SIP messages immediately.
I says that this resolves my problem partially because however I am still not able to make the whole procedure with suspending the transaction (without the Kamailio error).
In my case, it is not so important, but I imagine that in some cases the problem will persist.
Anton
From EVAPI module documentation: After evapi_async_relay() returns true, no relaying should happen in request_route(), it should be followed by exit.
Relay the event data given as parameter to connected applications. Before evaluating the parameter, the request processing is suspended using tm module (using the t_suspend()/t_continue() framework). The routing of the SIP request can be continued once event_route[evapi:message-received] is triggered. After evapi_async_relay() returns true, no relaying should happen in request_route(), it should be followed by exit;.

Resources