its my index.js file code.which i have taken a refrence from this link Javascript Azure Function to send email using SendGrid
module.exports = async function (context, req) {
var message = {
"personalizations": [ { "to": [ { "email": "testto#gmail.com" } ] } ],
from: { email: "testfrom#gmail.com" },
subject: "Azure news",
content: [{
type: 'application/json',
value: req.body.to
}]
};
context.done(null, {message});
};
This is the function.json file code.
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"name": "$return",
"type": "sendGrid",
"direction": "out",
"apiKey" : "SG.O1pazBKvS5Ox4YExYCY...",
"to": "df#mail.com ",
"from": "gh#gmail.com",
"subject": "SendGrid output bindings"
}
]
}
This is root directory local.setting.json file.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node",
"SENDGRID_API_KEY": "SG.O1pazBKvS5Ox4YExYCY...."
}
}
This is root directory host.json file
{
"version": "2.0",
"extensions": {
"sendGrid": {
"from": "Azure Functions <samples#functions.com>"
}
}
}
Following error i am getting in the console. Also , what is the correct way to send this email.? Reference taken for configuration file https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-sendgrid
Looks like you don't have the binding extension installed. You could either
Use Extension Bundles by updating your host.json to something like this
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
},
"extensions": {
"sendGrid": {
"from": "Azure Functions <samples#functions.com>"
}
}
}
Install the function extension using the dotnet CLI (Would need .NET Core installed locally)
dotnet add package Microsoft.Azure.WebJobs.Extensions.SendGrid --version 3.0.0
Related
How can I add custom colors to only output channel created by my extension?
Currently I have this package.json
{
"name": "mytestextension-output-colors",
"displayName": "My test extension - output colors",
"version": "0.0.1",
"publisher": "nobody",
"engines": {
"vscode": "^1.72.0"
},
"main": "./extension.js",
"activationEvents": [
"onStartupFinished"
],
"contributes": {
"languages": [
{
"id": "mytestextension-output",
"aliases": [],
"mimetypes": [
"text/x-code-output"
]
}
],
"grammars": [
{
"language": "mytestextension-output",
"scopeName": "text.mytestextension-output",
"path": "./mytestextension-output.tmLanguage.json"
}
],
"configuration": {
"type": "object",
"title": "My Test Extension - output colors"
},
"configurationDefaults": {
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "mytestextension-output-red",
"settings": {
"foreground": "#f00080"
}
}
]
}
}
}
}
extension.js
const window = require("vscode").window;
function activate() {
const out = window.createOutputChannel("myextension test output", "mytestextension-output");
out.appendLine(`red output`);
}
function deactivate() {}
module.exports = {
activate,
deactivate
};
mytestextension-output.tmLanguage.json
{
"$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
"name": "mytestextension-output",
"scopeName": "text.mytestextension-output",
"patterns": [ {
"match": ".*",
"name": "mytestextension-output-red"
}
]
}
Even though the grammar is set for mytestextension-output id/scope, it applied to and changes color to red in all output channels (git, tasks, extensions, etc)
What am I missing here?
Gist example
I tried to integrate cypress and slack. I'm able to get simple notifications such as pipeline status, alert, push or merge request. My requirement is to get notification like this.
Also I'm not able to integrate reportportal, I need to get more detailed for slack notification.
I tried to follow these instructions
My cypress.json file look like this.
"reporterOptions": {
"configFile": "reporterOpts.json",
"reporterEnabled": "spec, mocha-junit-reporter, #reportportal/agent-js-cypress, mochawesome",
"reportportalAgentJsCypressReporterOptions": {
"endpoint": "https://reportportal.mlsdevcloud.com/api/v1/",
"token": "445151-w6djb-ae48-awd86wd",
"launch": "no launch",
"project": "demo",
"description": "UAT",
"autoMerge": true
},
"mochaJunitReporterReporterOptions": {
"mochaFile": "cypress/results/results-[hash].xml"
}
},
"reports": [
{
"targets": [
{
"name": "slack",
"inputs": {
"url": "https://hooks.slack.com/services/T/secreatToken/"
}
}
],
"results": [
{
"type": "junit",
"files": ["cypress/results/results-[hash].xml"]
}
]
}
]
And this is suggested json file.
{
"reports": [
{
"targets": [
{
"name": "teams",
"inputs": {
"url": "<teams-incoming-webhook-url>"
},
"extensions": [
{
"name": "report-portal-analysis",
"inputs": {
"url": "<report-portal-base-url>",
"api_key": "<api-key>",
"project": "<project-id>",
"launch_id": "<launch-id>"
}
}
]
}
],
"results": [
{
"type": "testng",
"files": ["path/to/testng-results.xml"]
}
]
}
]
}
how to pass
"launch_id": ""
it is generated every time when build is triggered.
I have an Azure SignalR service setup with upstream. Negotiate is working, but I am getting a 404 error when trying to use connection.invoke('events', { ... });
In the SignalR event log, I am getting (irrelevant bits omitted):
{
"properties": {
"message": "Sending message during operation {hub}=map,{event}=events,{category}=messages got unexpected response with status code 404. Detail: ",
"type":"MessagingLogs",
"collection":"Serverless"
},
"operationName": "HttpHandlerUnexpectedResponse",
"callerIpAddress": "null"
}
What might be causing the 404?
There is a Azure Function app setup with an events function with the following bindings:
{
"disabled": false,
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
},
{
"type": "signalR",
"name": "$return",
"hubName": "map",
"direction": "out"
}
]
}
I believe the function app is getting setup correctly. I have the following setup as my upstream (with info replaced in the actual call:
<function_app_server>/runtime/webhooks/signalr?code=<signalr_extension_key>
Apparently the bindings have changed for Azure when using Upstream. The following bindings worked:
{
"bindings": [
{
"type": "signalRTrigger",
"name": "invocation",
"hubName": "map",
"category": "messages",
"event": "events",
"parameterNames": [
"message"
],
"direction": "in",
},
{
"type": "signalR",
"name": "signalRMessages",
"hubName": "map",
"connectionStringSetting": "AzureSignalRConnectionString",
"direction": "out"
}
]
}
module.exports = function (context, invocation) {
context.bindings.signalRMessages = [{
"target": "newMessage", // name of the client method to invoke
"arguments": [
context.bindingData.message // arguments to pass to client method
]
}];
context.done();
};
I've defined the security definitions.
"securityDefinitions": {
"Bearer": {
"type": "apiKey",
"in": "header",
"name": "Authorization"
}
},
And this is my path :
"/post/user": {
"get": {
"tags": [
"Authenticated User"
],
"summary": "All User's Posts",
"description": "",
"operationId": "user-posts",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "All user's posts.",
"schema": {
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"$ref": "#/definitions/Post"
}
}
}
}
}
},
"security": {
"Bearer": []
}
}
},
This is how I initialize my swagger-ui-express :
const swaggerUi = require('swagger-ui-express');
const swaggerDocument = require('./swagger.json');
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocument));
When I tried to login and add the token to the Authorize option in the top right and executed the protected path, Swagger will be loading forever. Even Swagger is not hitting the endpoint because there is no log printed in the server console.
Do you have any idea about this?
I use Nightwatch-Cucumber to automate my end2end tests and want to create a cucumber html report after test execution with cucumber-html-reporter, but I get an error while report generation by cucumber-html-reporter:
Unable to parse cucumberjs output into json: 'reports/cucumber.json' SyntaxError: reports/cucumber.json: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at Object.readFileSync (/Users/GRme/projects/e2e-web-tests/node_modules/jsonfile/index.js:69:17)
And I don't know why my generated cucumber.json is invalid.
I use the following versions:
"cucumber-html-reporter": "^2.0.0",
"nightwatch": "^0.9.16",
"nightwatch-cucumber": "^7.1.10",
This is my config in nightwatch.conf.js:
require('nightwatch-cucumber')({
cucumberArgs: [
'--tags', '#run',
'--require', 'timeout.js',
'--require', 'hooks.js',
'--require', 'features/step_definitions',
'--format', 'pretty',
'--format', 'json:reports/cucumber.json',
'features']
});
And this is the hooks.js, where my cucumber html report generation is executed:
const {client} = require('nightwatch-cucumber');
const {defineSupportCode} = require('cucumber');
var reporter = require('cucumber-html-reporter');
var options = {
theme: 'bootstrap',
jsonFile: 'reports/cucumber.json',
output: 'reports/cucumber_report.html',
reportSuiteAsScenarios: true,
launchReport: false,
//ignoreBadJsonFile: true,
name: 'NIKITA end2end tests',
brandTitle: 'NIKITA end2end tests',
storeScreenShots: true,
metadata: {
// "App Version": "0.0.1",
// "Test Environment": "AAT",
// "Browser": "Chrome XXX",
// "Platform": "Mac OS X",
}
};
defineSupportCode(({Before, After}) => {
Before(function() {
client.maximizeWindow();
});
After(function() {
reporter.generate(options);
});
});
My generated and apparently invalid cucumber.json looks like this:
[
{
"keyword": "Feature",
"line": 1,
"name": "only a test feature",
"tags": [],
"uri": "/Users/GRme/projects/e2e-web-tests/features/testFeature.feature",
"elements": [
{
"keyword": "Scenario",
"line": 4,
"name": "only a test Scenario",
"tags": [
{
"line": 3,
"name": "#run"
}
],
"id": "only-a-test-feature;only-a-test-scenario",
"steps": [
{
"arguments": [],
"keyword": "Before",
"result": {
"status": "passed",
"duration": 1
},
"hidden": true,
"match": {
"location": "/Users/GRme/projects/e2e-web-tests/hooks.js:24"
}
},
{
"arguments": [],
"keyword": "When ",
"name": "\"1\" seconds waiting",
"result": {
"status": "passed",
"duration": 2615
},
"line": 5,
"match": {
"location": "/Users/GRme/projects/e2e-web-tests/features/step_definitions/abstractStepDefinition.js:10"
}
},
{
"arguments": [],
"keyword": "After",
"result": {
"status": "passed",
"duration": 4
},
"hidden": true,
"match": {
"location": "/Users/GRme/projects/e2e-web-tests/hooks.js:28"
}
}
]
}
],
"id": "only-a-test-feature"
}
]
Generating the Cucumber Html Report via Jenkins with the Cucumber Reports Plugin runs successful.
So, how can I solve my problem and which framework (Nightwatch-Cucumber or cucumber-html-reporter) is the reason? And what is the invalid part of my generated cucumber.json?
Try to generate cucumber html report in a separate step of test execution. For example if you are using npm script use a separate npm script to generate the report. The problem with your approach is that in Cucumber.js global After hook the report is not created yet. That's why you are getting such an error. I suggest to use a separate node.js script to run cucumber-html-reporter.
I solved the problem by using Event Handler. I put the Cucumber report generation in such a Event Handler function for the event AfterFeatures and it works perfect for me.
More information you can find here.