telegram user phone number or id in dialogflow webhook - dialogflow-es

I have integration DialogFlow vs Telegram.
I am sending webhook at fullfilment.
How can i get user Telegram phone number and send it at webhook?
Thank you.

You won't get phone number from Telegram Bot API but you can extract user id. This is example payload you will receive in webhook (in request['originalDetectIntentRequest']['payload'] node):
{
'source':'telegram',
'data':{
'update_id':123456789.0,
'message':{
'from':{
'is_bot':False,
'username':'user_name',
'id':123456789.0,
'language_code':'pl',
'last_name':'Last Name',
'first_name':'First Name'
},
'chat':{
'type':'private',
'last_name':'Last Name',
'id':123456789.0,
'first_name':'First Name',
'username':'user_name'
},
'message_id':258.0,
'text':'user message',
'date':1564341923.0
}
}
}
The only way to get user's phone number is to ask him. You can find more information here: https://core.telegram.org/bots/2-0-intro#locations-and-numbers

Related

twitch js count the number of gift subscriptions

I am making a bot for the twitch platform, and now I have reached gift subscriptions, now I have the following command:
client.on('subgift', (channel, username, streakMonths, recipient, methods, userstate) => {
subGiftHandler(channel, username, streakMonths, recipient, methods, userstate)
})
function subGiftHandler(channel, username, streakMonths, recipient, methods, userstate) {
client.say(channel,
`Thank you #${username} for gifting a sub to ${recipient}.`
)
}
It's good when they give only one subscription at a time. But when, let's say, 10 subscriptions are given, and there are 10 such messages from the bot, it will be so-so.
How can I get the number of gift subscriptions, and add this to the condition to display a different message if there are more than one subscription?
I tried const senderCount = userstate["msg-param-sender-count"]
but it only returns false.
And if const senderCount = ~~userstate["msg-param-sender-count"]
then it only returns 0.
I using tmi.js

React-JS StripeCheckout get the Customer ID/Charge ID after successful purchase

I'm trying to get the Customer ID/Charge ID after the purchase and to send the Customer ID/Charge ID in database for future use.
import StripeCheckout from 'react-stripe-checkout';
onToken = async (token) => {}
<StripeCheckout
stripeKey='pk_test_51JG'
token={this.onToken}
amount={this.state.grandTotal * 100}
name='Payment'/>
The recommended way is to set up a webhook endpoint and subscribe to checkout.session.completed events: https://stripe.com/docs/payments/checkout/fulfill-orders#handle-the-event
Depending on what exactly you mean by "transaction ID" the information you need is likely already contained there, or can be retrieved from Stripe using the IDs available.

Connect to Password Protected Zoom Calls with Twilio Voice

Earlier I used to connect to Zoom calls as follows:
this.twilioClient.calls.create({
record: true,
recordingStatusCallback: process.env.POST_RECORDING_WEBHOOK,
url: process.env.TWILIO_HELLO_TWIML,
recordingStatusCallbackEvent: ['initiated', 'ringing', 'answered', 'completed'],
from: process.env.TWILIO_PHONE_NUMBER,
statusCallback: process.env.TWILIO_STATUS_WEBHOOK,
statusCallbackMethod: 'POST',
to: phoneNumber,
sendDigits: 'www' + <call_sid>+ #ww#',
});
However, now, if a call also has a meeting password as well, for example:
Meeting ID: 9_digit_number
Password: Some_alphanumeric_string
How should I modify my function for that?
Twilio developer evangelist here.
According to the Zoom documentation:
If the meeting requires a password, a phone-specific numeric password will be generated. You can find this password in the invitation listed below the dial-in numbers and meeting ID.
So you can use your code, you just need to find the phone-specific password.

Is it possible to send an SMS message with Twilio based on data from a MongoDB document and then update the document based on user response?

I am working on a little pet project where users can create a Goal and they will receive daily reminders of said goal using the Twilio API. Part of the Goal schema is phoneNumber which I store for the Twilio API. Currently my node server fires a helper function called initialMessage whenever a new document is created in my remote MongoDB database. initialMessage takes the goal as a parameter and has access to all of its data.
I want to add another layer of complexity and be able to ask the user via Twilio if they completed their goal today and based on whether they say Yes or No, update a nested responses object in the Goal schema that is { yes: 0, no: 0 } by default.
I set up ngrok and can handle SMS messages to a url on my express server, but I am having a hard time conceptualizing the flow for this to work, because I would need to retain the _id of the Goal that is sent from the initial message while waiting for a user response so I can call an updateOne function on my mongoDB cluster. Is this possible?
//Initial Message
const initialMessage = (goal) => {
console.log(`+1${goal.creatorPhoneNumber}`)
const messageBody = `Hi ${goal.creatorName.split(' ')[0]},
Thank you for setting a goal on Goaly!
We will send you a daily reminder for ${goal.goalTitle} starting on ${moment(goal.startDate).format("MMMM Do YYYY")}.`
client.messages
.create({
body: messageBody,
from: '+xxxxxxxxxx',
to: `+1${goal.creatorPhoneNumber}`
})
.then(message => {
console.log(goal._id);
});
}
//Goal Schema
const goalSchema = {
_id: String,
creatorName: String,
creatorPhoneNumber: String,
goalTitle: String,
goalDescription: String,
dailyAction: String,
noteToSelf: String,
createdOn: String,
startDate: String,
endDate: String,
creatorResponses: {
done: {
yes: Number,
no: Number
}
}
}
Twilio developer evangelist here.
Could you look up the goal by the creatorPhoneNumber instead of the _id when you receive the incoming message from your user? You'd likely want to create an index over creatorPhoneNumber to ensure it is performant.

In Bot Framework, what Unique ID should I use to save session?

I am using bot framework and I am saving the session.messageAddress so I can send the user a msg later. I want to track each unique user I get. In case if they send me another msg again I will know I have already received a msg from them earlier. What unique ID should I use to identify the user?
I was thinking of using session.message.address.conversation.id, is this correct?
Refer to https://learn.microsoft.com/en-us/azure/bot-service/bot-service-resources-identifiers-guide?view=azure-bot-service-3.0
Every bot and user has an account within each channel. The account contains an identifier (id) and other informative bot non-structural data, like an optional name.
Example: "from": { "id": "john.doe#contoso.com", "name": "John Doe" }
You should use session.message.user.id to identify the user. Using the conversation id won’t work because the user can start a new conversation with the bot by simply reloading the web chat page and a new conversation id will be generated.
Edit
I mistakenly wrote session.from.id to identify the user. The correct way to do it is session.message.user.id!
Say that the user John Doe is chatting to the bot through Skype then message.user.id = "john.doe#contoso.com" and message.user.name = "John Doe". And there you have it! your unique user id!
The session object will look like this:
"session":
{
/*...*/
"message":
{
/*...*/
"user":
{
"id": "john.doe#contoso.com",
"name": "John Doe"
}
}
}

Resources