Bot Framework API, reply to messages - botframework

I have registered Bot channels on Azure portal and enabled Skype support. I'm trying to create a reply to skype messages as described here.
I get user's message like: { ... 'type': 'message', 'id': '1579000...' ... }
And then use that id when sending POST to .../v3/conversations/{conversationId}/activities/1579000...
In a request body I also have 'replyToId': '1579000...'
The message, which is sent to skype, comes up without any quote inside (as usual message). What am I doing wrong? Do I understand how it should actually work (maybe this is not quoting, but something else)?

Related

Proactive message not working in MS Teams after bot is restarted

I have a proactive messaging endpoint that works fine when a user is actively engaged in a conversation. For example, one use case where user asks for invoice data to be retrieved, which happens asynchronously and is sent back via proactive message. This works fine. But if a try to continue a conversation weeks later, the continueConversation action is failing. If I go into teams and initiate a new conversation with the bot, then resending the proactive message (without changing anything) works again.
In one of my use cases, the bot needs to follow up with the user 1+ weeks in the future. So I need to figure out how to send a proactive message to a teams user even if they haven't recently conversed with the bot. I'm not sure why continueConversation isn't working because the conversation ID doesn't change (and hasn't changed in months, probably not ever).
Here is the function I am using to send the proactive message.
server.post('/api/notify', async (req, res) => {
//console.log(req.body);
try {
const conversationReference = req.body.conversationReference;
await adapter.continueConversation(conversationReference, async turnContext => {
// If you encounter permission-related errors when sending this message, see
// https://aka.ms/BotTrustServiceUrl
await turnContext.sendActivity(req.body.message);
});
res.setHeader('Content-Type', 'text/html');
res.writeHead(200);
res.write('<html><body><h1>Proactive messages have been sent.</h1></body></html>');
res.end();
} catch (error) {
console.log('Bad Request. Please ensure your message contains the conversation reference and message text.');
console.log(error);
appInsightsClient.trackTrace({
message: `${error.name} - ${path.basename(__filename)}`,
severity: 4,
properties: {'error':error.message,'callStack':error.stack, 'botName': process.env.botName}
});
res.setHeader('Content-Type', 'text/html');
res.writeHead(400);
res.write('<html><body><p>Bad Request. Please ensure your message contains the conversation reference and message text.</p></body></html>');
res.end();
}
});
As the link in my own code says,
If your bot is restarted, a user awaiting a proactive message cannot receive it unless they have messaged the bot again after it restarted.
So that was exactly what the issue was. But the instructions on that page aren't giving the full details. You have to add the class via const { MicrosoftAppCredentials } = require('botframework-connector') as well as set the serviceUrl to pass (which is already available at conversationReference.serviceUrl).
So with these changes I added MicrosoftAppCredentials.trustServiceUrl(conversationReference.serviceUrl); before I send the proactive message and it started working fine even after bot was restarted.

image appears in dialogflow chatbot but not shown in whatsapp chatbot and making twilio error

see update: Partial Solution
I'm using dailogflow and twilio to make whatsapp chatbot.
Text messages appears normally in both dialogflow and whatsapp.
Images appears only in dialogflow chatbot, but it is not working in whatsapp chatbot and makes error in twilio
This is the part of code which I'm adding to Inline Editor of DialogFlow fulfillment:
agent.add(new Card({
title: `Title: this is a card title`,
imageUrl: 'http://examplesitelink.com/image_name.png',
})
below the error message which I receive in twilio
MESSAGE
The URI scheme, of the URI null, must be equal (ignoring case) to 'http', 'https', 'ws', or 'wss'
......
HTTP retrieval failure
......
Possible Causes
Web server returned a 4xx or 5xx HTTP response to Twilio
Misconfigured Web Server
Network disruptions between Twilio and your web server
No Content-Type header attached to response
Content-Type doesn't match actual content, e.g. an MP3 file that is being served with Content-Type: audio/x-wav, instead of Content-Type: audio/mpeg
Is there anything I can do to solve this problem?
Partial Solution
Below a partial solution
I became able to send images to whats app via dialogflow fulfillment
First, in the 'package.json' I added twilio in dependencies, "twilio": "3.37.1" (check the latest version on npm twilio)
Second I added below code to send an image to whatsapp using its url, and it works
const client = require('twilio')('YOUR_ACCOUNT_SID', 'YOUR_AUTH_TOKEN'); /* change YOUR_ACCOUNT_SID and YOUR_AUTH_TOKEN to your own twilio account data */
client.messages
.create({
to: 'whatsapp:+13233633791', /* change it to your the number which you want to send the image to*/
from: 'whatsapp:+18007778888', /* change it to your the number which twilio sandbox provide, you can find it here: https://www.twilio.com/console/sms/whatsapp/sandbox */
body: "Hi Joe! Please find your boarding pass attached. Flight OA2345 departs at 11 pm PST.",
mediaUrl: 'https://emerald-coral-3661.twil.io/assets/2-OwlAir-Upcoming-Trip.PNG',
})
.then((message) => console.log(message.sid));
the problem now is:
In previous code, to is required, which means I have to specify the number which I want to send the image to, that looks odd, but the code will not work if I didn't specify to.
What I need to know is, how can I change: to: 'whatsapp:+13233633791', to any code can send the message to the current user who use whatsapp
I have also faced the same problem of not being able to send the media messages to any user that is using the chatbot currently. I found the solution to that in a youtube video, in which they have extracted the receiver mobile no. from the request object like below -
const data = request.body.originalDetectIntentRequest.payload;
const To = data.From;
const From = data.To;
Here the request object is the one you get when you create your dialogflow agent using the code below 'req' here-
app.post("/", express.json(), (req, res) => {
-------------------
-------------------
function handler() {
----------
}
intentMap.set("intent", handler);
}

How do I retrieve the sender number when using Twilio's messaging services with Copilot enabled?

I have a Twilio messaging service with Copilot and the sticky sender feature enabled.
I would like to view the phone number that Copilot assigns to my recipients when I send them a message.
With the Ruby client, I get a MessageContext object when I send a message, but it only has the
messaging service SID - the from method returns nil.
Currently, this is how I'm sending messages:
def send(from, to, message)
client = Twilio::REST::Client.new(ACCOUNT_SID, AUTH_TOKEN)
client.api.account.messages.create(
body: message,
messaging_service_sid: from,
to: to,
status_callback: BASE_URL + '/sms_status/status',
)
end
Twilio developer evangelist here.
I'm not sure, but you might not have the phone number at the time you make the API request using a messaging service. This request really just queues up the message to be sent.
I would check the message object once it has been sent. You have a status callback URL setup, so you should be able to either inspect the parameters sent to that URL or look up the message from the API using its SID and then get the number that was used.

Load testing bot with serviceUrl throws exception

System Information
SDK Language: Node.js
SDK Version: 3.8.3
Development Environment: localhost
Issue Description
Following the blogpost https://blog.botframework.com/2017/06/19/Load-Testing-A-Bot/ to load test the bot Im creating a "sink" service to send messages to the bot. Since it uses it as the serviceUrl in the message, the bot talks to the sink service for other purposes too.
I can post to the bot, but at one point when the bot is talking back it sends a message of type 'event' 'Debug' that has no conversation object in the address, resulting in an exception being thrown.
Expected Behavior
The bot sends activities back to the sink service
Actual Results
After activity type 'messge' and 'typing' have been sent, the debug event activity raises an exceptoin:
TypeError: Cannot read property 'id' of undefined
at ChatConnector.postMessage (/Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/bots/ChatConnector.js:459:82)
at /Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/bots/ChatConnector.js:165:27
at iterate (/Users/nico/workspace/ambitai/codereview/server/node_modules/async/lib/async.js:262:13)
at Object.async.forEachOfSeries.async.eachOfSeries (/Users/nico/workspace/ambitai/codereview/server/node_modules/async/lib/async.js:281:9)
at ChatConnector.send (/Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/bots/ChatConnector.js:159:15)
at RemoteSessionLogger.flush (/Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/RemoteSessionLogger.js:74:24)
at /Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/Session.js:638:26
at /Users/nico/workspace/ambitai/codereview/server/node_modules/async/lib/async.js:52:16
at Object.async.forEachOf.async.eachOf (/Users/nico/workspace/ambitai/codereview/server/node_modules/async/lib/async.js:236:30)
at Object.async.forEach.async.each (/Users/nico/workspace/ambitai/codereview/server/node_modules/async/lib/async.js:209:22)
at Session.onFinishBatch (/Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/Session.js:616:15)
at /Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/Session.js:430:27
at /Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/Session.js:606:17
at /Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/bots/UniversalBot.js:523:17
at /Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/bots/ChatConnector.js:178:36
at /Users/nico/workspace/ambitai/codereview/server/node_modules/async/lib/async.js:52:16
at /Users/nico/workspace/ambitai/codereview/server/node_modules/async/lib/async.js:269:32
at /Users/nico/workspace/ambitai/codereview/server/node_modules/async/lib/async.js:44:16
at /Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/bots/ChatConnector.js:167:25
at /Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/bots/ChatConnector.js:474:21
at Request._callback (/Users/nico/workspace/ambitai/codereview/server/node_modules/botbuilder/lib/bots/ChatConnector.js:508:37)
at Request.self.callback (/Users/nico/workspace/ambitai/codereview/server/node_modules/request/request.js:188:22)
Found the issue, when calling the bot endpoint, the activity must provide the conversation id. This was not specified in the blogpost. By adding conversation: { id: <id> } to the activity being posted it works

Does Amazon SNS use GET or POST to an http subscription?

I could not find anything documentation regarding method or format of message.
The Amazon Simple Notification Service (Amazon SNS) is using a HTTP POST to deliver a notification message, see the FAQ What are the different delivery formats/transports for receiving notifications?:
“HTTP”, “HTTPS” – Subscribers specify a URL as part of the
subscription registration; notifications will be delivered through an
HTTP POST to the specified URL.
The notification message format is documented in HTTP/HTTPS Notifications JSON Format (the Subscribe/Unsubscribe JSON Formats are documented in Appendix D: JSON Formats as well).

Resources