I'm trying to read a text file from WhatsApp and can find the filename in the intent, but not the file itself.
Also confused as to what the MIME type should be. Should "text/plain" be used for both shared text AND a shared text file? How does one differentiate between one and the other?
[IntentFilter(new[] { Intent.ActionSend },
Categories = new[] { Intent.CategoryDefault },
DataMimeType = #"text/plain", Icon = "#drawable/icon")]
void HandleSendIntent(Intent intent)
{
//extra1 = "myfile.txt"
var extra1 = intent?.GetStringExtra(Intent.ExtraText)?.Trim();
//extra2 = null
var extra2 = intent?.GetStringExtra(Intent.ExtraProcessText)?.Trim();
//uri = {content://com.whatsapp.provider.media/item/83019679-d3d1-4e43-805e-7a05734e88df}
Android.Net.Uri uri = (Android.Net.Uri)intent.GetParcelableExtra(Intent.ExtraStream);
string doc_id = "";
using (var c1 = ContentResolver.Query(uri, null, null, null, null))
{
c1.MoveToFirst();
string document_id = c1.GetString(0);
//doc_id = "myfile.txt":
doc_id = document_id.Substring(document_id.LastIndexOf(":") + 1);
}
//a = null
var a = Intent.GetParcelableArrayExtra("com.whatsapp");
//b = null
var b = Intent.GetByteArrayExtra("com.whatsapp");
//c = "text/plain"
var c = Intent.Type;
//
//Where is the file????
//
}
Related
I have a code that reads my Xslt templates from Resources but I have to make it reads from seperated files in root directory of application. So this is my code:
docs[0] = new DocumentReferenceType
{
ID = new IDType { Value = new Guid().ToString() },
IssueDate = new IssueDateType { Value = DateTime.Now },
DocumentType = new DocumentTypeType { Value = "xslt" },
Attachment = new AttachmentType
{
EmbeddedDocumentBinaryObject = new EmbeddedDocumentBinaryObjectType
{
filename = "customxslt.xslt",
encodingCode = "Base64",
mimeCode = "applicationxml",
format = "",
characterSetCode = "UTF-8",
Value = Encoding.UTF8.GetBytes(Properties.Resource1.XSLTFile)
}
}
};
return docs;
What should I write to "Properties.Resource1.XSLTFile" read from XSLTFile.xslt in root directory? I tried to write this:
string _filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
_filePath += #"\XSLTFile.xslt";
And I changed "Properties.Resource1.XSLTFile" with "_filePath " there but it gave me this error: "HTML conversion failed: XSLT compilation error"
i got help and i am sharing maybe there will be someone who needs it
string _filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
_filePath += #"\xslt\earsiv.xslt";
string xs = System.IO.File.ReadAllText(_filePath);
docs[0] = new DocumentReferenceType
{
ID = new IDType { Value = new Guid().ToString() },
IssueDate = new IssueDateType { Value = DateTime.Now },
DocumentType = new DocumentTypeType { Value = "xslt" },
Attachment = new AttachmentType
{
EmbeddedDocumentBinaryObject = new EmbeddedDocumentBinaryObjectType
{
filename = "customxslt.xslt",
encodingCode = "Base64",
mimeCode = "applicationxml",
format = "",
characterSetCode = "UTF-8",
Value = Encoding.UTF8.GetBytes(xs)
}
}
};
return docs;
I've managed to create a payment using the C# .NET SDK, however it keeps showing up as 'unapplied' when I check in QBO.
I am providing the Invoice ID and tried to follow their developer API documentation but I been at this so long now that maybe I am missing something?
The following code creates the payment but doesn't 'receive' the payment towards the invoice, is there something I missed or need to do in order for the two to be linked together?
Payment payment = new Payment
{
ProcessPayment = false,
CustomerRef = new ReferenceType { name = customer.DisplayName, Value = customer.Id },
CurrencyRef = new ReferenceType { type = "Currency", Value = "CAD" },
TotalAmt = amount,
TotalAmtSpecified = true
};
if (method == PaymentTypes.Cash)
{
var paymentType = paymentMethods.FirstOrDefault(o => o.Id == "1");
if (paymentType != null)
{
payment.PaymentMethodRef = new ReferenceType()
{name = paymentType.Name, Value = paymentType.Id};
}
}
if (method == PaymentTypes.DebitCard)
{
var paymentType = paymentMethods.FirstOrDefault(o => o.Id == "9");
if (paymentType != null)
{
payment.PaymentMethodRef = new ReferenceType()
{ name = paymentType.Name, Value = paymentType.Id };
}
}
if (method == PaymentTypes.CreditCard)
{
var paymentType = paymentMethods.FirstOrDefault(o => o.Id == "8");
if (paymentType != null)
{
payment.PaymentMethodRef = new ReferenceType()
{ name = paymentType.Name, Value = paymentType.Id };
}
}
List<LinkedTxn> linkedTxns = new List<LinkedTxn>
{
new LinkedTxn()
{
TxnId = invoice.Id,
TxnType = TxnTypeEnum.Invoice.ToString()
},
};
foreach (Line line in invoice.Line)
{
//line.Amount = amount;
//line.AmountSpecified = true;
line.Received = amount;
line.ReceivedSpecified = true;
line.DetailType = LineDetailTypeEnum.PaymentLineDetail;
line.DetailTypeSpecified = true;
line.LinkedTxn = linkedTxns.ToArray();
}
payment.DepositToAccountRef = new ReferenceType() { Value = "5" };
payment.Line = invoice.Line;
payment.PaymentRefNum = reference;
DataService dataService = new DataService(serviceContext);
dataService.Add<Payment>(payment);
This is not an answer. However there's too much to add to the comments. I'm hoping this will be a helpful starting point (if not I'll remove it later).
Firstly I'd suggest refactoring your code and parameterise your variables. Doing so you should be able to preform repeatable testing in isolation.
When you preform the dataService.Add<Payment>(payment), store the response object as it may offer clues on how the request was processed. Alternatively if this is suppressing error messages, you might want to try an use Postman to send HTTP requests. This may help determine what's parameters are missing/ incorrect.
Avoid creating objects that are partially assigned it makes it a lot easier to read 7 work out which properties need to be assigned.
Also if you have a look at Full update a payment section on https://developer.intuit.com/app/developer/qbo/docs/api/accounting/all-entities/payment
the json payload has an additional Line with the property TxnType set to CreditMemo. I would assume you'll need to add something like ReceivePayment or CreditCardPayment?
To refactor your code consider:
// TODO - Set variables for testing purposes.
// This can be added as params to a method.
decimal amount = 100;
string reference = "";
string invoiceId = ""; // invoice.Id
string customerDisplayName = ""; //customer.DisplayName
string customerId = ""; //customer.Id
string paymentName = "Cash"; // paymentType.Name
string paymentId = "1"; // paymentType.Id
List<Line> lines = new List<Line>(); // invoice.Line
if(lines.Count() == 0)
{
// TODO: You might want to check there are lines?
throw new ArgumentException("No invoice.");
}
Line[] invoiceLines = lines.Select(m => new Line()
{
AnyIntuitObject = m.AnyIntuitObject,
Amount = m.Amount,
AmountSpecified = m.AmountSpecified,
CustomField = m.CustomField,
Id = m.Id,
LineNum = m.LineNum,
Description = m.Description,
DetailType = LineDetailTypeEnum.PaymentLineDetail, //m.DetailType,
DetailTypeSpecified = true, //m.DetailTypeSpecified,
LinkedTxn = new List<LinkedTxn>
{
new LinkedTxn()
{
TxnId = invoiceId,
TxnType = TxnTypeEnum.Invoice.ToString() // TODO: Should this be ReceivePayment?
},
}.ToArray(), //m.LinkedTxn,
LineEx = m.LineEx,
Received = amount, //m.Received,
ReceivedSpecified = true // m.ReceivedSpecified
}).ToArray();
Payment payment = new Payment
{
ProcessPayment = false,
CustomerRef = new ReferenceType { name = customerDisplayName, Value = customerId },
CurrencyRef = new ReferenceType { type = "Currency", Value = "CAD" },
TotalAmt = amount,
TotalAmtSpecified = true,
DepositToAccountRef = new ReferenceType() { Value = "5" },
Line = invoiceLines, // Variable is for debugging purposes - it should be inline or call a method.
PaymentRefNum = reference,
PaymentMethodRef = new ReferenceType()
{
name = paymentName,
Value = paymentId,
}
};
DataService dataService = new DataService(serviceContext);
Payment results = dataService.Add<Payment>(payment);
var json = JsonConvert.SerializeObject(results);
Console.Write(json); // TODO - Use break point/ or write response somewhere for clues.
Hi I am developing a chatbot on amazon lex and I want to send a response card using the lambda function but on using response card function inside the close response format it gives the error of null exception. Can anyone tell the solution to it?
PS I am using FlowerOrder blueprint created by Nikki.
if (slots[greet] != null)
{
var validateGreet = ValidateUserGreeting(slots[greet]);
if (validateGreet.IsValid)
{
return Close(sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
ContentType = "PlainText",
Content = String.Format("Hello Kindly choose one option")
},
new LexResponse.LexResponseCard
{
Version = 1,
ContentType = "application/vnd.amazonaws.card.generic",
GenericAttachments =
{
new LexResponse.LexGenericAttachments
{
Buttons =
{
new LexResponse.LexButton
{
Text = "Shop Now",
Value = "Shop Now"
}
},
AttachmentLinkUrl = null,
Title = "Shopping",
SubTitle = "Sub Shopping",
ImageUrl = null
}
}
}
);
}
Exception:-
2020-06-09 17:31:20: Object reference not set to an instance of an object.: NullReferenceException at EVS_Test_Abbar_Lambda_Function.OrderWatchIntentProcessorTest.Process(LexEvent lexEvent, ILambdaContext context) in D:\AWS Project\Abbrar Projects\EVS_Test_Abbar_Lambda_Function\EVS_Test_Abbar_Lambda_Function\OrderWatchIntentProcessorTest.cs:line 52 at EVS_Test_Abbar_Lambda_Function.Function.FunctionHandler(LexEvent lexEvent, ILambdaContext context) in D:\AWS Project\Abbrar Projects\EVS_Test_Abbar_Lambda_Function\EVS_Test_Abbar_Lambda_Function\Function.cs:line 43
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )
Here is the solution to it since if you look at the structure of JSON it contains many models and lists and each has to be handled separately.
LexResponse.LexResponseCard lexResponseCard = new LexResponse.LexResponseCard();
List<LexResponse.LexGenericAttachments> ListlexGenericAttachments = new List<LexResponse.LexGenericAttachments>();
LexResponse.LexGenericAttachments lexGenericAttachments = new LexResponse.LexGenericAttachments();
List<LexResponse.LexButton> ListlexButton = new List<LexResponse.LexButton>();
LexResponse.LexButton lexButton = new LexResponse.LexButton();
lexButton.Text = "Yes Now";
lexButton.Value = "Yes";
ListlexButton.Add(lexButton);
lexGenericAttachments.AttachmentLinkUrl = "Link";
//lexGenericAttachments.AttachmentLinkUrl = null;
lexGenericAttachments.Title = "Shopping";
lexGenericAttachments.SubTitle = "Sub Shopping";
lexGenericAttachments.ImageUrl = "Link";
//lexGenericAttachments.ImageUrl = null;
lexGenericAttachments.Buttons = ListlexButton;
ListlexGenericAttachments.Add(lexGenericAttachments);
lexResponseCard.Version = 0;
lexResponseCard.ContentType = "application/vnd.amazonaws.card.generic";
lexResponseCard.GenericAttachments = ListlexGenericAttachments;
return Close(sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
ContentType = "PlainText",
Content = String.Format("Hello Kindly choose one option")
},
lexResponseCard
);
It may be your capitalization of key names. For example you have ContentType but it should be contentType as camelcase beginning with lowercase letters.
return Close(sessionAttributes,
"Fulfilled",
new LexResponse.LexMessage
{
contentType = "PlainText",
content = String.Format("Hello Kindly choose one option")
},
new LexResponse.LexResponseCard
{
version = 1,
contentType = "application/vnd.amazonaws.card.generic",
GenericAttachments =
{
new LexResponse.LexGenericAttachments
{
Buttons =
{
new LexResponse.LexButton
{
text = "Shop Now",
value = "Shop Now"
}
},
attachmentLinkUrl = null,
title = "Shopping",
subTitle = "Sub Shopping",
imageUrl = null
}
}
}
);
try just one Lex Response Card .
return Close(sessionAttributes,
"Fulfilled"
new LexResponse.LexResponseCard
{
version = 1,
contentType = "application/vnd.amazonaws.card.generic",
GenericAttachments =
{
new LexResponse.LexGenericAttachments
{
Buttons =
{
new LexResponse.LexButton
{
text = "Shop Now",
value = "Shop Now"
}
},
attachmentLinkUrl = null,
title = "Shopping",
subTitle = "Sub Shopping",
imageUrl = null
}
}
}
);
I am using C# implementation of netsuite api from web reference com.netsuite.webservices
I released filter fileSearch.basic by name (you can see it commented) it is working fine.
Please help to write function to achieve all attached files for current user. Something is wrong in this code, it filters nothing and showing me all files as it is without any filter. Please help me.
public static void GetFileAttachmentByCustomerId(string customerId)
{
using (NetSuiteService netSuiteService = GetNetSuiteService())
{
FileSearch fileSearch = new FileSearch();
// this works fine (filter files by name)
//SearchStringField nameSearchParams = new SearchStringField
//{
// #operator = SearchStringFieldOperator.contains,
// operatorSpecified = true,
// searchValue = "some name",
//};
//fileSearch.basic = new FileSearchBasic() { name = nameSearchParams };
// this code not filter files at all
{
RecordRef nsCustomerRef = new RecordRef
{
internalId = customerId,
type = RecordType.customer,
typeSpecified = true,
};
SearchMultiSelectField shopperSearchParam = new SearchMultiSelectField
{
#operator = SearchMultiSelectFieldOperator.anyOf,
operatorSpecified = true,
searchValue = new RecordRef[] { nsCustomerRef }
};
fileSearch.shopperJoin = new CustomerSearchBasic { internalId = shopperSearchParam };
}
SearchResult result = netSuiteService.search(fileSearch);
// Get connected objects
{
Customer customer = GetCustomerById(netSuiteService, customerId);
Account account = GetAccountById(netSuiteService, "301395"); //
Folder folder = GetFolderById(netSuiteService, "3962");
}
File file = (File)result.recordList.First();
byte[] fileContent = GetFileContentByInternalId(file.internalId);
}
}
.
Try this:
var nsCustomerRef = new RecordRef
{
internalId = "4",
type = RecordType.employee,
typeSpecified = true,
};
var currentUser = new SearchMultiSelectField()
{
operatorSpecified = true,
#operator = SearchMultiSelectFieldOperator.anyOf,
searchValue = new List<RecordRef>() {nsCustomerRef}.ToArray()
};
var fileSearchBasic = new FileSearchBasic() {owner = currentUser};
var fileSearch = new FileSearch() { basic = fileSearchBasic };
var result = netSuiteService.search(fileSearch);
var file = (File)result.recordList.First();
I'm trying to send a mail chimp campaign using asp.net, actually i created successfully the campaign and i can see it through my profile but also i want to send it through my code here is my code so if any one can help!!
private static void CreateCampaignAndSend(string apiKey, string listID)
{
Int32 TemplateID = 0;
string campaignID = string.Empty;
// compaign Create Options
var campaignCreateOpt = new campaignCreateOptions
{
list_id = listID,
subject = "subject",
from_email = "cbx#abc.com",
from_name = "abc",
template_id = TemplateID
};
// Content
var content = new Dictionary<string, string>
{
{"html", "Lots of cool stuff here."}
};
// Conditions
var csCondition = new List<campaignSegmentCondition>();
var csC = new campaignSegmentCondition {field = "interests-" + 123, op = "all", value = ""};
csCondition.Add(csC);
// Options
var csOptions = new campaignSegmentOptions {match = "all"};
// Type Options
var typeOptions = new Dictionary<string, string>
{
{"offset-units", "days"},
{"offset-time", "0"},
{"offset-dir", "after"}
};
// Create Campaigns
var campaignCreate = new campaignCreate(new campaignCreateInput(apiKey, EnumValues.campaign_type.plaintext, campaignCreateOpt, content, csOptions, typeOptions));
campaignCreateOutput ccOutput = campaignCreate.Execute();
campaignSendNow c=new campaignSendNow();
List<Api_Error> error = ccOutput.api_ErrorMessages; // Catching API Errors
if (error.Count <= 0)
{
campaignID = ccOutput.result;
}
else
{
foreach (Api_Error ae in error)
{
Console.WriteLine("\n ERROR Creating Campaign : ERRORCODE\t:" + ae.code + "\t ERROR\t:" + ae.error);
}
}
}