I'm trying to get a Skype bot up and running based off of the echo example but I'm struggling to make a successful POST to my app. When I send a post to /v1/chat I get back a status of 201 (successful creation), and nothing in the body. My console.log does not print anything either, which leads me to believe that the botService.on('personalMessage', ...) function is not being run. Does anyone have any insight into how these POST requests should be formatted? I cannot seem to find anything in the documentation.
My code:
const fs = require('fs');
const restify = require('restify');
const skype = require('skype-sdk');
const botService = new skype.BotService({
messaging: {
botId: '28:<bot’s id="ID176db9ab-e313-4d76-a60c-bc2a280e9825">',
serverUrl : "https://apis.skype.com",
requestTimeout : 15000,
appId: process.env.APP_ID,
appSecret: process.env.APP_SECRET
}
});
botService.on('contactAdded', (bot, data) => {
console.log('contact added');
bot.reply('Hello ${data.fromDisplayName}!', true);
});
botService.on('personalMessage', (bot, data) => {
console.log('message incoming');
console.log(data);
bot.reply('Hey ${data.from}. Thank you for your message: "${data.content}".', true);
});
const server = restify.createServer();
server.post('/v1/chat', skype.messagingHandler(botService));
const port = process.env.PORT || 8080;
server.listen(port);
console.log('Listening for incoming requests on port ' + port);
Final Edit & Solution: I think the problem caused by Heroku somehow(it could be something with their free tier ,1 dyno). After some effort, I uploaded the program to Azure, and it is now working perfectly.
Potential Solution: You need to change the server address in the server.post command. If you run your program in "https:\www.yourwebsite.com/v1/chat" , you need to modify this;
server.post('/v1/chat', skype.messagingHandler(botService));
to this;
server.post('https:\\www.yourwebsite.com/v1/chat', skype.messagingHandler(botService));
Of course, don't forget to specify your app id, bot id, and app secret. If you don't have one, you need to generate a password in your Skype application page.
I have the exact problem with the OP. I followed the tutorial, and it doesn't specify how to modify our code to comply with our server. So, after running the program it only returns this;
{"code":"ResourceNotFound","message":"/ does not exist"}
In the Echo example in the Skype Bot Webpage; it says;
"We'll assume the bot's URL for messaging was set to https://echobot.azurewebsites.net/v1/chat during registration."
Make sure that Procfile and worker processes are setup.
My bot is working fine on heroku itself
Related
Am newbie in node.js and would like to grab all events types.
In this case i already did my homework.I found from far this one.
In link, Continuosly throwing below error.
Error :
TypeError: esl.createCallServer is not a function
I am expecting : If any call has been started and forward to the gateway.So on the realtime would like to get gateway name in node.js to check which gateway is using
Might be possible,I understand is not correct way but below also one more try to achieve this but that not giving me gateway information.
call_handler = require('seem');
const esl = require("esl");
const port = 4041;
const server = esl.server(call_handler).listen(port);
server.listen(port, function() {
console.log("Server listening for connection requests on socket localhost:"+port);
});
esl.client(call_handler).connect(4050);
server.on("connection", function(chunk) {
console.log("Connection has been established");
chunk.on("data", (data) => {
console.log("Channel Park info");
var data_string = data.toString();
var data_arr= data_string.replace(/\r\n/g, "\r").replace(/\n/g, "\r").split(/\r/);
var data_array= JSON.stringify( data_arr );
console.log(data_array);
chunk.end();
});
});
Node.js server have port is 4050.
From Freeswitch dialplan, I am executing below line
<action application="socket" data="127.0.0.1:4041 full"/>
Expected Output :
Whenever call is bridge on any gateway then after and before complete call am able to get bridge line from node.js
Also parameters which are added in dialplan as set/export that also must be get on node.js
Anyone like to share some hints for this problem ?
This isn’t a specific issue question, but I’m trying to wrap my head around the concept of REST APIs and calling an API within your own API.
For example, if I develop an App called “BeesBees”, where users can buy bees, and I have a database of logins and passwords and obviously the bees, and how much each cost, I understand that I can used my own apps BeesBees API to get the list of bees (and if I make it open for other people, they can also use my GET /bees point to get, well, the bees)
But if I want to allow customers to buy the bees, and I don’t want to build a whole platform for doing so, so I integrate Stripe - could I have a POST /:users/charges/:priceOfBee API call that, in turn, called the Stripe API function somewhere somehow? For example, pointing to the URL of a Node.js project that will make the charge using Stripe’s Node.js SDK.
Or, in a case like this, would it be better to just implement the Stripe SDK for my device’s platform and make the charge using the device?
I have no code base so there’s nothing to pick apart, but I couldn’t think of anywhere else to ask, sorry y’all
You can certainly wrap APIs with other APIs, it's really just a form of composition, delegate to other services where it makes sense to do so.
Stripe integration might well be a good example of where it could make sense to follow this pattern. You certainly don't want to roll your own payment service.
Here's a trivial example of a local Express server making an API request:
const express = require("express");
const port = 3000;
const app = express();
const request = require('request');
app.get("/api/example", (req, res) => {
// Make external REST request here...
let options = {
url: 'https://httpbin.org/get',
qs: { parameter1: 42 },
json: true
}
request(options, (err, response, body) => {
if (err) {
res.status(500).send(err.message);
} else {
res.status(200).send(body);
}
});
});
var server = app.listen(3000, function () {
var host = server.address().address;
var port = server.address().port;
console.log('running at http://' + host + ':' + port)
});
console.log(`Serving at http://localhost:${port}`);
This is my first time working with node.js and i have to connect it to Luis, what i tried to do so far is a simple example available in the docs where the bot repeats what the user says and it gave an error as i seemingly am linking LUIS to node.js badly although I referred to the docs https://learn.microsoft.com/en-us/azure/cognitive-services/luis/luis-nodejs-tutorial-build-bot-framework-sample
precisely
// app.js - register LUIS endpoint API
var recognizer = new builder.LuisRecognizer(process.env.LUIS_MODEL_URL);
bot.recognizer(recognizer)
;
My code
var restify = require('restify');
var builder = require('botbuilder');
var http = require('http');
var recognizer = new builder.LuisRecognizer(MY_PATH_TO_LUIS_HTTP);
bot.recognizer(recognizer);
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: MY_ID,
appPassword:MY_PASS
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
// Receive messages from the user and respond by echoing each message back (prefixed with 'You said:')
var bot = new builder.UniversalBot(connector, function (session) {
session.send("You said: %s", session.message.text);
});
So again what i'm trying to do is connect the Luis successfully to node.js then run the output in the cmd and test it in the bot framework channel emulator.
Kindly note that i have tested the code without adding
var http = require('http');
var recognizer = new builder.LuisRecognizer(MY_PATH_TO_LUIS_HTTP);
bot.recognizer(recognizer);
at first and it worked fine and i know that what i set in LuiS is different than what this node.js should do(repeat my words) but I'm just still getting a feel of how to link things.
Edit : I got this error
so i went to the command line and used this command npm install --save recognizer then imported to my code above by adding var recognizer = require ('recognizer');
still not working.
You are going in the right direction. The main issue is that you are doing
bot.recognizer before bot is declared :) (you are doing it at the bottom of the code)
Also, I believe that what it's missing is defining the intents methods that will handle the responses from LUIS.
You might want to check the following resources:
Recognize intents and entities with LUIS
The intelligence-LUIS Node.js sample
I have used IIS to locally host my bot like so: https: //localhost/MyBot. Currently when I try to connect to my bot in the bot emulator I get a POST 500 error, and am unable to send messages. I am new to this and most documentation for publishing a bot to a local server is limited. I can however successfully open this link from my browser.
Am I experiencing this error because I don't have the https: //localhost/Bridget/api/messages directory/url? I tried creating Virtual Directories in IIS but that did not help solve my problem. Do I need tunneling software? Is there a simple tutorial for deploying a bot locally using IIS and connecting to it via the bot emulator?
Here is the error I see in the emulator:
Bot Emulator Error
Using ngrok tunneling software this is what I see:
NGROK Bot Emulator Error
Here is the code that processing incoming POST messages:
/// <summary>
/// POST: api/Messages
/// Receive a message from a user and reply to it
/// </summary>
public async Task<HttpResponseMessage> Post([FromBody]Activity activity)
{
if (activity.Type == ActivityTypes.Message)
{
// Strip any #mentions
Mention[] m = activity.GetMentions();
for (int x = 0; x < m.Length; x++)
{
if (m[x].Mentioned.Id == activity.Recipient.Id)
{
if (m[x].Text != null)
{
activity.Text = activity.Text.Replace(m[x].Text, "");
}
}
}
await stateClient.BotState.SetUserDataAsync(activity.ChannelId, activity.From.Id, userData);
await Conversation.SendAsync(activity, () => new Dialogs.RootDialog());
}
else if (activity.Type == ActivityTypes.Invoke)
{
// Some Code...
}
else
{
HandleSystemMessage(activity);
}
var response = Request.CreateResponse(HttpStatusCode.OK);
return response;
}
Am I experiencing this error because I don't have the https: //localhost/Bridget/api/messages directory/url?
Both your screenshots show you trying to connect to /api/messages, which you say you don't have, so naturally, you are going to get an error.
Please post the portion of your bot code to show where you are listening for the messages. For example, a NodeJS bot would have something like:
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
The last line shows the connecting listening for message at /api/messages in the current application (being run by NodeJS using the restify library). What does your's have?
I fixed the issue, it was because IIS was not allowing POST requests. All I did was go to Request filtering and added the verb POST:
IIS POST Fix
I am trying to receive data sent from my client adobe air application in node.js server running on Heroku, but with no success.
This is how i am sending the data:
var loader : URLLoader = new URLLoader();
var request : URLRequest = new URLRequest("http://127.0.0.1:5000");
request.method = URLRequestMethod.GET;
loader.dataFormat = URLLoaderDataFormat.TEXT;
var variables:URLVariables = new URLVariables();
variables.data = 'this is data';
request.data = variables;
loader.addEventListener(Event.COMPLETE, onRestaurantObjectLoadComplete);
loader.load(request);
And my Node.js code for receiving requests :
app.get('/',function (request, res) {
console.log("received request data" + request.data );
});
app.listen(port, function() {
console.log("Listening on " + port);
});
The requests come to the server, and i am able to send the answer to the client, but data is always undefined.
Also, if i try to send data using POST method i get a Stream error in AIR application.
What would be the correct way of sending data to node.js server from AIR application?
EDIT: I managed to make it work locally, but when i upload it to heroku, it doesnt work.
I am sending the request to http://: (same as i did locally but myHerokuApp.com was localhost) and i keep getting a stream error.
What would have to be the correct URL to send requests to?
It seems it only does not work on the Simulator, once on testing on a real device it will work with the URL given by Heroku.
Still don't know how to make it work on the Simulator though.