Sending a webhook AND and a message in Pinescript v5 - webhooks

It appears that through the alert() function you can code a message to be sent, but what about the webhook?
I would like to use capitalise.ai, and they require to set in the alert both a webhook (https://tvwebhook.capitalise.ai) and a message, for example {"alertId": "b2f0d9f2-a848-48e4-8218-70350b24xxxx"} which will trigger a specific action, for example to buy or to sell.
Fact is, if I set in the UI an alert for a strategy I have created in Tradingview, there will be only one alert for all the possible events, and therefore only one message, but then how can I tell Capitalise.ai if the alert is for selling or buying?
I could do something like
if enterLong
alert("message 1))
else if enterShort
alert("message2"))
But then where do I put the webhook?
Thank you

You need different messages for different orders.
Check out this tutorial.

Your code must include something like this :
alert(jsondata, alert.freq_once_per_bar)
with jsondata a string in the json format.
Then your jsondata (your message) will be sent to your webhook.
To create the weebhook, look in the Alert Menu from your Tradingview Chart :
Choose the nae of your strategy in the Condition (Bybit Bot in the screenshot),
and create a 'Open-ended alert' alert :
Then go on the notification menu to give the url for the webhook :

I do something like this with a discord alert. Create your message in the script and not in the message box on the alert fly out.
I use this in a library
export GetDiscordJson(string userName, string avatar_url, string content, string title, string url, string description, string _fields, string _footer, string _authObject, string clr) =>
//parameters with _ lead are already formatted for the json end object
_username = jsonKeyValuePair("username", userName)
_avatarUrl = jsonKeyValuePair("avatar_url", avatar_url)
_content = jsonKeyValuePair("content", content)
_title = jsonKeyValuePair("title", title) // title = ticker
_url = jsonKeyValuePair("url", url)
_description = jsonKeyValuePair("description", description)
_color = jsonKeyValuePair("color", clr)
_embeds = str.format("\"embeds\":[{0}\n{1},\n{2},\n{3},\n{4},\n{5},\n{6},\n{7}\n{8}]", "{", _authObject, _title, _url, _description, _color, _fields, _footer, "}")
str.format("{0}\n{1},\n{2},\n{3},\n{4}\n{5}", "{",_username, _avatarUrl, _content, _embeds, "}")
Then in the indicator call it on each kind of alert
if enterLong
content = w.GetDiscordJson(_botName, _avatarURL, contMessage, syminfo.ticker, _titleURL, chartTimeframe, _fields, _footerObject, _authObject, _color )
alert(content, alert.freq_once_per_bar)

Simply put the webhook json string you get from capitalise into the alert(Capitalise-string,alert-frequency) command in your script. and then you can based on condition in your script decide which capitalise string to send. The alarm setup can only be done once with just the capitalise webhook URL, and leaving the message box empty.
Hope that’s understandable 😀

Related

How to get a segment of "member.activity" and how to send custom status' (discord.py)

My whois command is meant to send what the specified user's activity but instead it gives a long reply. I want it to send the activity type and name. Also is there a way for the bot to send a person's custom status
Code:
whois_embed = discord.Embed(timestamp=datetime.datetime.utcnow(), color = 0x00ceea)
whois_embed.add_field(name = "Activity", value = member.activity, inline = False)
await ctx.send(embed = whois_embed)
What the bot sends:
Activity
<Activity type=<ActivityType.watching: 3> name='over 3 servers' url=None details=None application_id=None session_id=None emoji=None>
You'll need to look at the attributes like declared in the docs.
To get the name of the activity use
activityName = member.activity.name
And to get the type use
activityType = member.activity.type
But since member.activity.type is not a string, it will print as something like ActivityType.custom. You could use a dict or something to convert it to a string though.
whois_embed = discord.Embed(timestamp=datetime.datetime.utcnow(), color = 0x00ceea)
whois_embed.add_field(name = "Activity", value = member.activity.name, inline = False)
await ctx.send(embed = whois_embed)

Google Form Search and Pull Spreadsheet Data

Hi I have google spreadsheet that contains customers' ID and their shipping status. I want to create google form where customers are able to input each of their own ID, with the return that the google form shows their shipping status.
I tried to look for solutions in internet but there was no luck. I am not really good in programming, i hope there is answer to this problem without having me to do some hard programming.
The sample case can be seen in here: https://docs.google.com/spreadsheets/d/14vSAeZxEJTzbNLLYEiref6qt-CMqiVi8alheLcIBugM/edit?usp=sharing
Google form should show something a little bit like is shown in cell D1:E3.
Where customers can fill the form with their own customer id, and the google form shows the status.
Consideration
There is no way to respond back in a Google Form directly. You can't show custom validation messages after From submission either.
Proposed solution
What about using email addresses additionally to the customerID to retrieve the shipping status? In this way you can easily build a notification system that will send an email if a matching customer ID is found in your spreadsheet.
To build such system you will have to build a Form with a Trigger.
It is required a bit of programming but I will try to cover the most important parts the best I can:
Adapt your Database structure
Add the customers email addresses in the column C in order to be able to retrieve it using the same customer ID.
| A | B | C |
|----+--------+-------|
| ID | STATUS | EMAIL |
Build the Form Trigger
In the Form you are using click on the 3 dots from the top menu and select Script Editor. Here you will write the code that will power your notification system.
function installTrigger() {
// This function instructs the program to trigger the checkID function whenever a form response is submitted
ScriptApp.newTrigger('checkID')
.forForm(FormApp.getActiveForm())
.onFormSubmit()
.create();
}
function checkID(e) {
// This function will parse the response to use the customer ID to retrieve email address and shipping status from the Spreadsheet Database
var responses = e.response.getItemResponses(); // Gets the form responses
var id = responses[0].getResponse(); // Assuming the first answer (index 0) is the customer ID)
var found = SpreadsheetApp.openById('spreadsheet_id')
.getRange('Sheet1!A1:C8') // The spreadsheet cells range in A1 Notation
.getValues() // Retrieve their values in rows
.filter((row) => row[0] == id); // Filter the rows for the provided customer ID
if (found) {
var status = found[0][1]; //Column B
var email = found[0][2]; //Column C
var subject = "Shipping Status";
var message =
`Hello!
The status of the order number ${id} is: ${status}.`
MailApp.sendEmail(email, subject, message);
}
}
Install the trigger
From the Script Editor top menu run the installTrigger() function: Run>Run function>installTrigger.
You are done
Following these steps you have successfully set up the notification system. Now you can start sharing the Form link and accept responses.
References
Installable Triggers
Mail App

Asp.Net MVC ValidationSummary HTML error message

I've been asked to include a link in an error message when the Email address for a registration is already in use.
The validation for this property is done with a IValidatableObject.Validate function on the model. My validate function looks like so...
Public Overridable Function Validate(validationContext As ValidationContext) As IEnumerable(Of ValidationResult) Implements IValidatableObject.Validate
Dim results = New List(Of ValidationResult)()
....
If Not EmailAvailable(Email) Then
results.Add(New ValidationResult("The email address is not available. Forgot Password?", {"Email"}))
End If
Return results
End Function
In my views, I'm using a custom "MyValidationSummary" extension function to format the errors nicely.
The extension function does this...
....
Dim ul = New TagBuilder("ul")
For Each key In helper.ViewData.ModelState.Keys
For Each e In helper.ViewData.ModelState(key).Errors
Dim li = New TagBuilder("li") With {
.InnerHtml = helper.Encode(e.ErrorMessage)
}
ul.InnerHtml += li.ToString()
Next
Next
container.InnerHtml += ul.ToString()
Return New MvcHtmlString(container.ToString())
I know I could just remove helper.Encode, and just output the message as raw html, but this feels a bit hacky.
I'm trying to find a nice way to be able to selectively include html in the messages, while still retaining the default behaviour of encoding plain text messages.
What I thought of doing, is create a custom ValidationResult class, which optionally would include a HTMLString property, so that I can, if I choose, include HTML in the messages.
I can do this, but I don't know if there is any way to get at this custom ValidationResult from MyValidationSummary.
update:
For the time being, I've just added a placeholder tag into the error message, which I then substitute with the actual link in my MyValidationSummary extension method. It's very hacky, but it will work until I've found a better way to do it.

Aegis Implicit Mail AIM AlternateView in MimeMailMessage

I am using AIM Aegis Implicit Mail to send Implicit ssl mails.
When using subject and body in a mail message all is fine, however when I use alternate views my mai lhas an empty body. This alternate view setup works with mailmessage and has html and text body depending on the reciving client but I must use MimeMailMessage which looks ok in the debug code but is empty when recivied in the mailbox.
Here's the code:
string plainTextBody = "Welkom.";
AlternateView plainTextView =
AlternateView.CreateAlternateViewFromString(
plainTextBody, null, MediaTypeNames.Text.Plain);
plainTextView.ContentType = new System.Net.Mime.ContentType("text/plain");
mail.AlternateViews.Add(plainTextView);
string htmlBody = #"<html><body><img src=""cid:logo""><br /> Welkom </body></html>";
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
htmlView.ContentType = new System.Net.Mime.ContentType("text/html");
string imageSource = Path.Combine(HttpRuntime.AppDomainAppPath, #"Content\Images\Logob.png");
LinkedResource PictureRes = new LinkedResource(imageSource, MediaTypeNames.Image.Jpeg);
PictureRes.ContentId = "logo";
htmlView.LinkedResources.Add(PictureRes);
mail.AlternateViews.Add(htmlView);
Aim is not providing AlternativeView, however you can use inline attachments to put your images and directly set HTML code in your message body. try to download the sample code and have a look on how inline attachments are working

Creating a case in plugin, want to use its ticketnumber immediately

I have a plugin where i am creating a new case and I want to send an email out as it is created including its ticketnumber. I have attempted just to call this in the plugin but it is coming back saying that it is not present in the dictionary. I know this field is populated using CRM's own autonumbering so what i'm guessing is happening is that my plugin is firing and creating the case but then i'm trying to use this field before the autonumber has completed.
So is there a way that i can get my plugin to "wait" until this field is available and then use it?
Thanks
EDIT: Code below:
string emailBody = entity.Attributes["description"].ToString();
int bodyLength = emailBody.Length;
int textStart = emailBody.IndexOf(">") + 1;
int newLength = bodyLength - (textStart + 7);
string description = emailBody.Substring(textStart, newLength);
//create complaint
Entity complaint = new Entity("incident");
complaint["description"] = description;
complaint["ts_case_type"] = 717750001;
complaint["ts_registration_datetime"] = DateTime.Now;
complaint["ownerid"] = Owner;
complaint["customerid"] = Organisation;
Service.Create(complaint);
As a side I would suggest sending the email with a workflow if possible, it will be far easier to maintain in the long run and quicker to implement in the short.
In any case to answer your question, from what you have here you need to update your code to retrieve the ticketnumber once you have created the incident. You can do this with a Retrieve message.
For example:
//Create the complaint
Entity complaint = new Entity("incident");
//This is the information that is being sent to the server,
//it will not be updated by CRM with any additional information post creation
complaint["description"] = description;
complaint["ts_case_type"] = 717750001;
complaint["ts_registration_datetime"] = DateTime.Now;
complaint["ownerid"] = Owner;
complaint["customerid"] = Organisation;
//Capture the id of the complaint, we will need this in a moment
Guid complaintId = Service.Create(complaint);
//complaint["ticketnumber"] <-- The server does not populate this information in your object
//Retrieve the ticketnumber from the incident we just created
Entity complaintRetrieved = service.Retrieve("incident", complaintId, new ColumnSet("ticketnumber"));
//Get the ticketnumber
String ticketNumber = (String)complaintRetrieved.Attributes["ticketnumber"];
Like James said in comment, if you just want to send email with some case properties, it is best to do that with workflow (on case create).
In your plugin, ID is generated, and you can get it with:
entity.Attributes["ticketnumber"]

Resources