When I use WebHook method, this method sends old update. How can I prevent this?
else if (text != null && text.Equals("متن ارسال شود") && (update.Message.Chat.Id == WebApiApplication.chatId1 || update.Message.Chat.Id == WebApiApplication.chatId2)) {
WebApiApplication.SenderCount = 0;
int i = 0;
String[] Array;
TelBotEntities1 db = new TelBotEntities1();
int count = db.SenderBots.Count();
Array = new string[count];
foreach(var dbItem in db.SenderBots) {
Array[i] = dbItem.ChannelId;
i++;
}
Telegram Webhook will automatically resend failed updates, you can see it via getWebhookInfo pending_update_count parameter.
You can't prevent this, just ignore first few updates after start program.
Related
I am exploring Microsoft Computer Vision's Read API (asyncBatchAnalyze) for extracting text from images. I found some sample code on Microsoft site to extract text from images asynchronously.It works in following way:
1) Submit image to asyncBatchAnalyze API.
2) This API accepts the request and returns a URI.
3) We need to poll this URI to get the extracted data.
Is there any way in which we can trigger some notification (like publishing an notification in AWS SQS or similar service) when asyncBatchAnalyze is done with image analysis?
public class MicrosoftOCRAsyncReadText {
private static final String SUBSCRIPTION_KEY = “key”;
private static final String ENDPOINT = "https://computervision.cognitiveservices.azure.com";
private static final String URI_BASE = ENDPOINT + "/vision/v2.1/read/core/asyncBatchAnalyze";
public static void main(String[] args) {
CloseableHttpClient httpTextClient = HttpClientBuilder.create().build();
CloseableHttpClient httpResultClient = HttpClientBuilder.create().build();;
try {
URIBuilder builder = new URIBuilder(URI_BASE);
URI uri = builder.build();
HttpPost request = new HttpPost(uri);
request.setHeader("Content-Type", "application/octet-stream");
request.setHeader("Ocp-Apim-Subscription-Key", SUBSCRIPTION_KEY);
String image = "/Users/xxxxx/Documents/img1.jpg";
File file = new File(image);
FileEntity reqEntity = new FileEntity(file);
request.setEntity(reqEntity);
HttpResponse response = httpTextClient.execute(request);
if (response.getStatusLine().getStatusCode() != 202) {
HttpEntity entity = response.getEntity();
String jsonString = EntityUtils.toString(entity);
JSONObject json = new JSONObject(jsonString);
System.out.println("Error:\n");
System.out.println(json.toString(2));
return;
}
String operationLocation = null;
Header[] responseHeaders = response.getAllHeaders();
for (Header header : responseHeaders) {
if (header.getName().equals("Operation-Location")) {
operationLocation = header.getValue();
break;
}
}
if (operationLocation == null) {
System.out.println("\nError retrieving Operation-Location.\nExiting.");
System.exit(1);
}
/* Wait for asyncBatchAnalyze to complete. In place of this wait, can we trigger any notification from Computer Vision when the extract text operation is complete?
*/
Thread.sleep(5000);
// Call the second REST API method and get the response.
HttpGet resultRequest = new HttpGet(operationLocation);
resultRequest.setHeader("Ocp-Apim-Subscription-Key", SUBSCRIPTION_KEY);
HttpResponse resultResponse = httpResultClient.execute(resultRequest);
HttpEntity responseEntity = resultResponse.getEntity();
if (responseEntity != null) {
String jsonString = EntityUtils.toString(responseEntity);
JSONObject json = new JSONObject(jsonString);
System.out.println(json.toString(2));
}
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
There is no notification / webhook mechanism on those asynchronous operations.
The only thing that I can see right know is to change the implementation you mentioned by using a while condition which is checking regularly if the result is there or not (and a mechanism to cancel waiting - based on maximum waiting time or number of retries).
See sample in Microsoft docs here, especially this part:
// If the first REST API method completes successfully, the second
// REST API method retrieves the text written in the image.
//
// Note: The response may not be immediately available. Text
// recognition is an asynchronous operation that can take a variable
// amount of time depending on the length of the text.
// You may need to wait or retry this operation.
//
// This example checks once per second for ten seconds.
string contentString;
int i = 0;
do
{
System.Threading.Thread.Sleep(1000);
response = await client.GetAsync(operationLocation);
contentString = await response.Content.ReadAsStringAsync();
++i;
}
while (i < 10 && contentString.IndexOf("\"status\":\"Succeeded\"") == -1);
if (i == 10 && contentString.IndexOf("\"status\":\"Succeeded\"") == -1)
{
Console.WriteLine("\nTimeout error.\n");
return;
}
// Display the JSON response.
Console.WriteLine("\nResponse:\n\n{0}\n",
JToken.Parse(contentString).ToString());
I want to create a custom module, which log some activity of prestashop. For instance, when ever an order get complete, I log the user id, time, amount and device.
For this matter I think I have to use the hook which be called after placing an order; however, I couldn't find a source that listed all the hooks related to checkout process or order creation. Could any one help me to find the hook responsible for this job, or provide me by some resource of prestashop 1.6 hooks
I found it and maybe it could be useful for others:
first of all I added two hook to my install and two constatnts:
const HOOK_NEW_ORDER = 1;
const HOOK_ACTION_ORDER_STATUS_POST_UPDATE = 2;
actionValidateOrder & actionOrderStatusPostUpdate
if (!parent::install() ||
!$this->registerHook('actionValidateOrder') ||
!$this->registerHook('actionOrderStatusPostUpdate') ||
!Configuration::updateValue('AR_ADMIN_CLUB', 'customer club') ||
!$this->installModuleTab() ||
!$this->installDB() ||
!$this->registerHook("displayBackOfficeHeader") ||
!$this->insertInitData() ||
!$this->createFolders()
)
then I added two method to handle these hooks:
public function hookActionValidateOrder($params)
{
if (Module::isEnabled($this->name)) {
$this->hookOrderProcess(self::HOOK_NEW_ORDER, $params);
}
}
and
public function hookActionOrderStatusPostUpdate($params)
{
if (Module::isEnabled($this->name) && (!isset($GLOBALS['hookNewOrder']) || $GLOBALS['hookNewOrder'] != 1)) {
$this->hookOrderProcess(self::HOOK_ACTION_ORDER_STATUS_POST_UPDATE, $params);
}
}
finally I added the method to do the actions I needed, based on every order status changes:
private function hookOrderProcess($hook, $params)
{
if ($hook == self::HOOK_NEW_ORDER) {
$id_shop = $params['order']->id_shop;
$shop_name = $shop_info->name;
$GLOBALS['hookNewOrder'] = 1;
} elseif ($hook == self::HOOK_ACTION_ORDER_STATUS_POST_UPDATE) {
$order_id = $params['id_order'];
$order_info = new Order($params['id_order']);
$id_shop = $order_info->id_shop;
$shop_info = new Shop($id_shop);
$order_status = $order_info->getCurrentState();
$customer_id = $order_info->getCustomer()->id;
$group_id = $order_info->getCustomer()->id_default_group;
if($order_status == 5){
$this->actoin_first($order_id, $group_id, $customer_id);
} elseif($order_status == 6){
$this->actoin_second($order_id, $group_id, $customer_id,'all');
}elseif($order_status == 7){
$this->actoin_third($order_id, $group_id, $customer_id);
}
}
}
I can't seem to get data into an event
public LeadListScheduleController() throws ParseException {
eventModel = new DefaultScheduleModel();
for (int i = 0; i < leadList.size(); i++)
{
if((leadList.get(i).next_action != null && !leadList.get(i).next_action.isEmpty())&&(leadList.get(i).next_action_date != null && !leadList.get(i).next_action_date.isEmpty()))
eventModel.addEvent(new DefaultScheduleEvent(""+leadList.get(i).next_action+" "+leadList.get(i).business_name + " - " +leadList.get(i).id, nextLeadActionDate(leadList.get(i).next_action_date), nextLeadActionDate(leadList.get(i).next_action_date)));
}
What I want to do is add the variable leadList.get(i).id to the call as the data object, if I add it to the end of this constructor it goes in as a Style Class.
Anyone see a easy way to get it in there?
Data needs to be an object. It has to be declared as an object before passing in.
I am currently developing a testing framework for a web data entry application that is using the Telerik ASP.Net framework and have run into a blocker. If I step through my code in debug mode the test will find the text box that I am looking for and enter some test data and then save that data to the database. The problem that I am running into is that when I let the test run on it's own the test fails saying that it couldn't fine the column that was declared. Here is my code:
/*Method to enter test data into cell*/
private TableCell EditFieldCell(string columnHeader)
{
var columnIndex = ColumnIndex(columnHeader);
if (columnIndex == -1)
throw new InvalidOperationException(String.Format("Column {0} not found.", columnHeader));
return NewRecordRow.TableCells[columnIndex];
}
/*Method to return column index of column searching for*/
public int ColumnIndex(string columnHeader)
{
var rgTable = GridTable;
var rgCount = 0;
var rgIndex = -1;
foreach (var rgRow in rgTable.TableRows)
{
foreach (var rgElement in rgRow.Elements)
{
if (rgElement.Text != null)
{
if (rgElement.Text.Equals(columnHeader))
{
rgIndex = rgCount;
break;
}
}
rgCount++;
}
return rgIndex;
}
My thinking is that something with my nested for loops is presenting the problem because the rgIndex value that is returned when I let the program run is -1 which tells me that the code in the for loops isn't being run.
TIA,
Bill Youngman
Code that gets the table Column index. You need to pass the Table(verify that the table exists while debug):
public int GetColumnIndex(Table table, string headerName)
{
ElementCollection headerElements = table.TableRows[0].Elements; //First row contains the header
int counter = 0;
foreach (var header in headerElements)
{
if (header.ClassName != null && header.ClassName.Contains(headerName)) //In this case i use class name of the header you can use the text
{
return counter;
}
counter++;
}
// If not found
return -1;
}
Hi can some one please tell me how to copy one data store to another in dojo. I tried it in following way but it doesn't work. Here I'm try to copy data from jsonStore to newGridStore.
jsonStore.fetch({query:{} , onComplete: onComplete});
var onComplete = function (items, request) {
newGridStore = null;
newGridStore = new dojo.data.ItemFileWriteStore({
data : {}
});
if (items && items.length > 0) {
var i;
for (i = 0; i < items.length; i++) {
var item = items[i];
var attributes = jsonStore.getAttributes(item);
if (attributes && attributes.length > 0) {
var j;
for (j = 0; j < attributes.length; j++) {
var newItem = {};
var values = jsonStore.getValues(item, attributes[j]);
if (values) {
if (values.length > 1) {
// Create a copy.
newItem[attributes[j]] = values.slice(0, values.length);
} else {
newItem[attributes[j]] = values[0];
}
}
}
newGridStore.newItem(newItem);
}
}
}
}
Based on the comments asked above. You are trying to copy values to a new Store for the single reason to be able to detect which values have changes and then save them individually, without having to send the entire store.
This approach is totally wrong.
Dojo has isDirty() and offers you the ability to revert() a store back to it's original values. It knows which values have changed and you don't need to do this.
Take a look at the bog standard IFWS here: http://docs.dojocampus.org/dojo/data/ItemFileWriteStore
Make sure you read everything from here: http://docs.dojocampus.org/dojo/data/ItemFileWriteStore#id8
What you want to do is create your own _saveCustom method which you will override your store with, and then when you save, you will be able to see which values have changed.
Click on the demo at the very bottom of the page. It shows you EXACTLY how do to it using _saveCustom