PHP Messengerbot : Stuck User during test - php

I working on a BotMan based Messenger chatbot. I set up everything, tried to test out, everything went fine, but I got stuck.
I wanted to send an image as a response from my bot to my Facebook profile. It sent the image, but after it I got stuck: It tries to send the message again and I see in nGrok, that I have an 500 error request from my webhook.
I tried the following:
comment out the code to debug
restart the webserver
restart nGrok and set up a new webhook with the new address
restart computer than do the earlier
Nothing is helped from the following. With other Facebook profile I can "speak" with it (I got the good responses for my test cases), but the first profile is stuck. How to "unstuck" it?
EDIT:
This is the object, what tries to send, but gains error 500:
{
"object": "page",
"entry": [
{
"id": "1718785685111526",
"time": 1518649220812,
"messaging": [
{
"sender": {
"id": "1718785685111526"
},
"recipient": {
"id": "1702775193145548"
},
"timestamp": 1518641306603,
"message": {
"is_echo": true,
"app_id": 813542108832080,
"mid": "mid.$cAAZBynpFHa9nx1ij61hlhNatNiJj",
"seq": 353844,
"attachments": [
{
"type": "image",
"payload": {
"url": "https://scontent-ort2-2.xx.fbcdn.net/v/t34.0-12/28001431_2003444363312322_578145807_n.jpg?_nc_ad=z-m&_nc_cid=0&oh=7088ad6e09a1c9851a967c8193ea3bf4&oe=5A871570"
}
}
]
}
}
]
}
]
}

Related

PHP able to receive post request with a raw text but its giving error when post same data raw json

I'm posting data to my API endpoint. it's simple JSON data. But I'm getting error 404 when posting data as raw JSON but if I post the same data at the same endpoint as raw text its works.
working as raw text
getting error 404 as raw JSON
<?php
var_dump(http_response_code());
echo "hello";
var_dump($_POST);
echo file_get_contents("php://input");
I have removed all code from the API end point and just trying to print post data.
Sample JSON :
{
"object": "whatsapp_business_account",
"entry": [
{
"id": "456",
"changes": [
{
"value": {
"messaging_product": "whatsapp",
"metadata": {
"display_phone_number": "123456789",
"phone_number_id": 123456789
},
"contacts": [
{
"profile": {
"name": "NAME"
},
"wa_id": 123456789
}
],
"messages": [
{
"from": 123456789,
"id": "wamid.ID",
"timestamp": 123456789,
"text": {
"body": "MESSAGE_BODY"
},
"type": "text"
}
]
},
"field": "messages"
}
]
}
]
}
I have checked JSON and it's a valid JSON. no special character but still unable to solve this issue.
One more thing its working on my local machine under XAMPP but not on Linux shared server.

Send Current URL link to A Discord Webhook

So, basically I need a way to send the current URL link to A Discord webhook.
So for example, the URL would be https://www.example.com and I need that link to send to my Discord webhook.
Is there any way someone could help me with this? If this is not possible, are there any alternative methods?
I would recommend you first reading this—it explains in detail how to format the payload so that it renders as a message in Discord properly, you can even use markdown!
Second, I'm not sure what language you want to code this in, but here's a simple example using Python and httpx
The idea to take away here is
Pick a client library
Study the Discord webhook message format
Create a client for HTTP
Set the logic to send the payload to the webhook you want
Create and send the payload with the formatted webhook message in a POST request
data = {
"username": "Webhook",
"avatar_url": "https://i.imgur.com/4M34hi2.png",
"content": "Text message. Up to 2000 characters.",
"embeds": [
{
"author": {
"name": "Birdie♫",
"url": "https://www.reddit.com/r/cats/",
"icon_url": "https://i.imgur.com/R66g1Pe.jpg"
},
"title": "Title",
"url": "https://google.com/",
"description": "Text message. You can use Markdown here. *Italic* **bold** __underline__ ~~strikeout~~ [hyperlink](https://google.com) `code`",
"color": 15258703,
"fields": [
{
"name": "Text",
"value": "More text",
"inline": true
},
{
"name": "Even more text",
"value": "Yup",
"inline": true
},
{
"name": "Use `\"inline\": true` parameter, if you want to display fields in the same line.",
"value": "okay..."
},
{
"name": "Thanks!",
"value": "You're welcome :wink:"
}
],
"thumbnail": {
"url": "https://upload.wikimedia.org/wikipedia/commons/3/38/4-Nature-Wallpapers-2014-1_ukaavUI.jpg"
},
"image": {
"url": "https://upload.wikimedia.org/wikipedia/commons/5/5a/A_picture_from_China_every_day_108.jpg"
},
"footer": {
"text": "Woah! So cool! :smirk:",
"icon_url": "https://i.imgur.com/fKL31aD.jpg"
}
}
]
}
import httpx # pip install httpx, or poetry add httpx
with httpx.Client() as client:
request = client.post("https://www.discordwebhook.com", data=data) # needs to be a POST
print(request.status_code)

PHP Quickbooks SDK - Batch requests and handling failures

I've building out a small app that connects to a Quickbooks API via an SDK. The SDK provides batch operations to help reduce the number of API requests needed.
However, I'm hoping to make a large amount of requests (ie: bulk deletes, uploads in the 100s/1000s). I've gotten the deletes to work, however, now I'm hoping to integrate Laravel's Queue system so that any items in the $batch that fail (due to these business-rules or other reasons) are sent to a worker who will reattempt them after waiting a minute .
Below is an example of a delete request.
class QuickBooksAPIController extends Controller
{
public function batchDelete(Request $request, $category)
{
$chunks = array_chunk($request->data, 30);
foreach ($chunks as $key => $value) {
$batch[$key] = $this->dataService()->CreateNewBatch();
foreach ($value as $id) {
$item = $this->dataService()->FindById($category, $id);
$batch[$key]->AddEntity($item, $id, "delete");
}
$batch[$key]->Execute();
}
return response()->json(['message' => 'Items Deleted'], 200);
}
}
The documentations are a bit sparse for my scenario though. How can I get the failed batch items on order to try again?
Is using batches even the right choice here? Because I have to hit the API anyway to get the $item... which doesn't make sense to me (I think I'm doing something wrong there).
EDIT:
I intentionally sent out a request with more then 30 items and this is the failure message. Which doesn't have the values that didn't make the cut.
EDIT#2:
Ended up using array_chunk to separate the payload into 30 items (which is the limit of the API). Doing so helps process many requests. I've adjusted my code above to represent my current code.
How can I get the failed batch items on order to try again?
If you look at Intuit's documentation, you can see that the HTTP response the API returns contains this information. Here's the example request they show:
{
"BatchItemRequest": [
{
"bId": "bid1",
"Vendor": {
"DisplayName": "Smith Family Store"
},
"operation": "create"
},
{
"bId": "bid2",
"operation": "delete",
"Invoice": {
"SyncToken": "0",
"Id": "129"
}
},
{
"SalesReceipt": {
"PrivateNote": "A private note.",
"SyncToken": "0",
"domain": "QBO",
"Id": "11",
"sparse": true
},
"bId": "bid3",
"operation": "update"
},
{
"Query": "select * from SalesReceipt where TotalAmt > '300.00'",
"bId": "bid4"
}
]
}
And the corresponding response:
{
"BatchItemResponse": [
{
"Fault": {
"type": "ValidationFault",
"Error": [
{
"Message": "Duplicate Name Exists Error",
"code": "6240",
"Detail": "The name supplied already exists. : Another customer, vendor or employee is already using this \nname. Please use a different name.",
"element": ""
}
]
},
"bId": "bid1"
},
{
"Fault": {
"type": "ValidationFault",
"Error": [
{
"Message": "Object Not Found",
"code": "610",
"Detail": "Object Not Found : Something you're trying to use has been made inactive. Check the fields with accounts, customers, items, vendors or employees.",
"element": ""
}
]
},
"bId": "bid2"
},
{
"Fault": {
"type": "ValidationFault",
"Error": [
{
"Message": "Stale Object Error",
"code": "5010",
"Detail": "Stale Object Error : You and root were working on this at the same time. root finished before you did, so your work was not saved.",
"element": ""
}
]
},
"bId": "bid3"
},
{
"bId": "bid4",
"QueryResponse": {
"SalesReceipt": [
{
"TxnDate": "2015-08-25",
"domain": "QBO",
"CurrencyRef": {
"name": "United States Dollar",
"value": "USD"
},
"PrintStatus": "NotSet",
"PaymentRefNum": "10264",
"TotalAmt": 337.5,
"Line": [
{
"Description": "Custom Design",
"DetailType": "SalesItemLineDetail",
"SalesItemLineDetail": {
"TaxCodeRef": {
"value": "NON"
},
"Qty": 4.5,
"UnitPrice": 75,
"ItemRef": {
"name": "Design",
"value": "4"
}
},
"LineNum": 1,
"Amount": 337.5,
"Id": "1"
},
{
"DetailType": "SubTotalLineDetail",
"Amount": 337.5,
"SubTotalLineDetail": {}
}
],
"ApplyTaxAfterDiscount": false,
"DocNumber": "1003",
"PrivateNote": "A private note.",
"sparse": false,
"DepositToAccountRef": {
"name": "Checking",
"value": "35"
},
"CustomerMemo": {
"value": "Thank you for your business and have a great day!"
},
"Balance": 0,
"CustomerRef": {
"name": "Dylan Sollfrank",
"value": "6"
},
"TxnTaxDetail": {
"TotalTax": 0
},
"SyncToken": "1",
"PaymentMethodRef": {
"name": "Check",
"value": "2"
},
"EmailStatus": "NotSet",
"BillAddr": {
"Lat": "INVALID",
"Long": "INVALID",
"Id": "49",
"Line1": "Dylan Sollfrank"
},
"MetaData": {
"CreateTime": "2015-08-27T14:59:48-07:00",
"LastUpdatedTime": "2016-04-15T09:01:10-07:00"
},
"CustomField": [
{
"DefinitionId": "1",
"Type": "StringType",
"Name": "Crew #"
}
],
"Id": "11"
}
],
"startPosition": 1,
"maxResults": 1
}
}
],
"time": "2016-04-15T09:01:18.141-07:00"
}
Notice the separate response object for each request.
The bId value is a unique value you send in the request, which is then echo'd back to you in the response, so you can match up the requests you send with the responses you get back.
Here's the docs:
https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/batch#sample-batch-request
Is using batches even the right choice here?
Batches make a lot of sense when you are doing a lot of things all at once.
The way you're trying to use them is... weird. What you should probably be doing is:
Batch 1
- go find all your items
Batch 2
- delete all the items
Your existing code doesn't make sense because you're trying to both find the item and delete the item in the exact same batch HTTP request, which isn't possible via the API.
I intentionally sent out a request with more then 30 items and this is the failure message.
No, it's not. That's a PHP error message - you have an error in your code.
You need to fix the PHP error, and then look at the actual response you're getting back from the API.

Docusign not hitting webhook URL

I'm trying to use webhooks, but no events are being sent to my application via the webhook url. So far I was able to configure and send correctly envelopes with enough information to monitor status, but when things changes in the envelopes, nothing happens, I mean, no requests are made to my webhook URL, at all.
My app is doing good, so if I manually hit (GET) https://subdomain.app.com/docusign/webhook, it works fine and it shows both on my app log and Nginx log. But viewing, signing and completing documents/envelopes are not generating events to the webhook url.
I noticed that, in the examples, the events are capitalized for recientEvents, but not for envelopeEvents, is this right?
Is there anything else to be configured?
Is is possible to see this information in the Docusign web interface (https://account-d.docusign.com/logout#/username)? I would like to check if this data is correctly set in the envelope.
Here's the envelope request (minus some data):
{
"documents": [{
"documentId": 1,
"name": "XXXXXXXXX.pdf",
"documentBase64": "XXXXXXX"
}],
"recipients": {
"signers": [{
"tabs": {
"signHereTabs": [{
"documentId": 1,
"recipientId": 1,
"pageNumber": 1,
"anchorString": "recipient_signature"
}]
},
"name": "XXXXXX",
"email": "XXXX#XXXX.co",
"recipientId": 1,
"clientUserId": XXXX
}]
},
"eventNotification": {
"url": "https:\/\/subdomain.app.com\/docusign\/webhook",
"loggingEnabled": "true",
"envelopeEvents": [{
"envelopeEventStatusCode": "sent"
}, {
"envelopeEventStatusCode": "delivered"
}, {
"envelopeEventStatusCode": "completed"
}, {
"envelopeEventStatusCode": "declined"
}, {
"envelopeEventStatusCode": "voided"
}, {
"envelopeEventStatusCode": "sent"
}, {
"envelopeEventStatusCode": "sent"
}],
"recipientEvents": [{
"recipientEventStatusCode": "Sent"
}, {
"recipientEventStatusCode": "Delivered"
}, {
"recipientEventStatusCode": "Completed"
}, {
"recipientEventStatusCode": "Declined"
}, {
"recipientEventStatusCode": "AuthenticationFailed"
}, {
"recipientEventStatusCode": "AutoResponded"
}]
},
"status": "sent",
"emailSubject": "XXXXXX",
"brandId": "XXXXXXXXXX"
}
EDIT:
Entering Connect -> Log/Failures looks like the system is not really performing as it should, because sometimes I get
And some other times I get an empty list. Going in the publish option, when it's working I get a list of documents/envelopes, and I see the last envelope I sent there, which looks fine.
You can view your recent connect logs/failures at the Docusign Admin web application. See instructions to use the Admin site here
If your connect messages were not sent, to the listener URL you provided, they should show up in the failures section.
API : You can also view your connect logs/failure using the connectEvents api's
Here is some documentation for troubleshooting connect issues.
The capitalization of status codes is not an issue. They are case insensitive.

Regarding stackify-api, data not displaying in stackify logs

Currently, I am using a trial version.When hit from the php code using the monolog and syslog, the logs are displayed in the stackify log management console.But as mentioned in
https://github.com/stackify/stackify-api/blob/master/endpoints/POST_Log_Save.md
When I hit using POSTMAN tool, the response I receive is
{
"success": true,
"took": 46
}
But the logs are not displayed in the stackify logs console.
My postman request headers:
Content-Type,Accept,X-Stackify-PV,X-Stackify-Key are provided.
Body:
{
"Env": "Prod",
"ServerName": "rajeshwar-latitude-3450",
"AppName": "Stackifytest",
"Msgs": [
{
"Msg": "debug message",
"Level": "DEBUG"
},
{
"Msg": "info message",
"Level": "DEBUG"
}
]
}
I'm pretty sure the EpochMs field is required.
Please check the readme file. It says which fields are required.
https://github.com/stackify/stackify-api/blob/master/endpoints/POST_Log_Save.md

Categories