I can request user's one-time location using Telegraf framework:
bot.start(ctx =>
const keyboard = Extra.markup(markup =>
markup
.resize()
.keyboard([
markup.contactRequestButton('Give phone number'),
markup.locationRequestButton('Give location')
])
)
ctx.replyWithMarkdown('a message to user', keyboard)
)
Is there any way to request live location instead?
i hope it helps:
bot.onText(/^\/place_order/, function (msg, match) {
var option = {
"parse_mode": "Markdown",
"reply_markup": {
"one_time_keyboard": true,
"keyboard": [[{
text: "My phone number",
request_contact: true
}], ["Cancel"]]
}
};
bot.sendMessage(msg.chat.id, "How can we contact you?", option).then(() => {
bot.once("contact",(msg)=>{
var option = {
"parse_mode": "Markdown",
"reply_markup": {
"one_time_keyboard": true,
"keyboard": [[{
text: "My location",
request_location: true
}], ["Cancel"]]
}
};
bot.sendMessage(msg.chat.id,
util.format('Thank you %s with phone %s! And where are you?', msg.contact.first_name, msg.contact.phone_number),
option)
.then(() => {
bot.once("location",(msg)=>{
bot.sendMessage(msg.chat.id, "We will deliver your order to " + [msg.location.longitude,msg.location.latitude].join(";"));
})
})
})
})
Related
this is my first time using stripe and I am getting an error Must provide source or customer. once I went live. In the test mode I used "tok_mastercard" as my source but clearly when I went live it isn't valid. What am I missing here please help.
This is my POST request in the backend
stripe.charges
.create({
amount: req.renter.rent * 100,
currency: "usd",
source: req.body.token,
application_fee_amount: req.renter.rent * 0.05 * 100,
transfer_data: {
//the destination needs to not be hard coded it needs to
//come from what property the renter is in
destination: req.renter.stripeConnectId,
// destination: "acct_1GOCMqDfw1BzXvj0",
},
})
.then((charge) => {
console.log(req.renter);
res.send(charge);
})
.catch((err) => {
console.log(err);
});
});
this is my two functions in the frontend using react-native and node
handleCardPayPress = async () => {
try {
this.setState({ loading: true, token: null });
const token = await stripe.paymentRequestWithCardForm({
// Only iOS support this options
smsAutofillDisabled: true,
requiredBillingAddressFields: "full",
prefilledInformation: {
billingAddress: {
name: "",
line1: "",
line2: "",
city: "",
state: "",
country: "US",
postalCode: "",
email: "",
},
},
});
this.setState({ loading: false, token });
} catch (error) {
this.setState({ loading: false });
}
};
makePayment = async () => {
try {
//Mate the payment
const response = await unitApi.post("/payments", {
data: {
amount: this.state.renter.rent,
currency: "usd",
token: this.state.token,
},
});
Alert.alert("Success!", `Confirmation ID: ${response.data.id}`, [
{ text: "Done" },
]);
console.log(response.data);
// navigate("Home");
} catch (err) {
//failiur and showing the error message
console.log(err);
Alert.alert("Failed!", "Card declined.", [{ text: "Declined" }]);
}
};
Odds are pretty good that this.state.token doesn't contain what you think it does in the unitApi.post() function call; I'd recommend logging that and seeing if that helps, and also logging req.body.token server-side.
I have a callback_query when users hit on a purchase button. The callback_query is to send an invoice to the user, but it is throwing the above error.
bot.on('callback_query', (ctx) => {
let data = ctx.callbackQuery.data
if (data.includes('purchase') == true) {
return handlePurchase(ctx)
}
})
function handlePurchase(ctx) {
let data = ctx.callbackQuery.data
let itemId = data.split(':')[1]
let invoice = {
chat_id: ctx.callbackQuery.from.id,
title: "Title",
description: "Description",
payload: itemId.toString(),
provider_token: stripeToken,
start_parameter: itemId.toString(),
currency: "USD",
need_phone_number: true,
need_shipping_address: true,
photo_url: the_image_url,
prices: [{
label: "Item",
amount: 1000
}]
}
return ctx.replyWithInvoice(invoice)
}
I also attempted to use ctx.telegram.sendInvoice(invoice) instead but the bot did not send an invoice to the user, ie the bot did not respond at all.
I have a Slack command which displays a button. When I click on this button I need to display a modal. For this, after clicking it I do this:
const dialog = {
callback_id: "submit-ticket",
elements: [
{
hint: "30 second summary of the problem",
label: "Title",
name: "title",
type: "text",
value: "teste"
},
{
label: "Description",
name: "description",
optional: true,
type: "textarea"
},
{
label: "Urgency",
name: "urgency",
options: [
{ label: "Low", value: "Low" },
{ label: "Medium", value: "Medium" },
{ label: "High", value: "High" }
],
type: "select"
}
],
submit_label: "Submit",
title: "Submit a helpdesk ticket"
};
const modalInfo = {
dialog: JSON.stringify(dialog),
token, // this is correct
trigger_id: actionJSONPayload.trigger_id
};
// This is what I get confused with...
// Method 1
slack.dialog.open(modalInfo).catch(err => {
console.log("ERROR: ", err);
});
// end method 1
// Method 2
sendMessageToSlackResponseURL(actionJSONPayload.response_url, modalInfo);
...
function sendMessageToSlackResponseURL(responseURL: any, JSONmessage: any) {
const postOptions = {
headers: {
"Content-type": "application/json"
},
json: JSONmessage,
method: "POST",
uri: responseURL
};
request(postOptions, (error: any, response: any, body: any) => {
if (error) {
console.log("----Error: ", error);
}
});
}
// end method 2
I get always Error: invalid_trigger using method1 when this trigger is something that my button is generating automatically.
Method 2 doesn't throw any error but doesn't open any modal/dialog either.
The official documentation is not quite clear and I don't know if I need to call dialog.open or views.open. Either way, the last one is not available from Slack package
This is also the button I'm displaying before anything:
const message = {
attachments: [
{
actions: [
{
name: "send_sms",
style: "danger",
text: "Yes",
type: "button",
value: "yes"
},
{
name: "no",
text: "No",
type: "button",
value: "no"
}
],
attachment_type: "default",
callback_id: "alert",
color: "#3AA3E3",
fallback: "We could not load the options. Try later",
text: "Do you want to alert by SMS about P1 error/fix?"
}
],
text: "P1 SMSs"
};
Copy a modal from here
const headers = {
headers: {
"Content-type": "application/json; charset=utf-8",
"Authorization": "Bearer " + token
}
};
const modalInfo = {
"token": token,
"trigger_id": reqBody.trigger_id,
"view": slack.modal
};
axios
.post("https://slack.com/api/views.open", modalInfo, headers)
.then(response => {
const data = response.data;
if (!data.ok) {
return data.error;
}
})
.catch(error => {
console.log("-Error: ", error);
});
But most importantly, when we do some changes to our app we need to reinstall it and also when we do it, the token changes and this is something I couldn't find on the documentation
i am new to botpress and trying to make simple order bot with botpress. but not using messenger,etc just trying to make simple question answer bot. in available example on github uses content.yml but it gives error
[Renderer] Renderer not defined (#welcome)
at /Applications/MAMP/htdocs/botpress-pro-nightly-2018-12-24-darwin-x64/pizza/node_modules/botpress/src/renderers/index.js:163:13
index.js
module.exports = bp => {
Object.keys(renderers).forEach(name => {
bp.renderers.register(name, renderers[name])
})
bp.hear(/GET_STARTED|hello|hi|test|hey|holla/i, (event, next) => {
console.log(event);
event.reply('#welcome')
var yes=event.welcome.quick_replies[0].payload;
bp.logger.info('answer:', yes);
})
}
so i use this type of code in renderers.js it works but not able to fetch reply
module.exports = {
text: data => {
return {text: data.text, typing: !!data.typing}
},
'#welcome': data => ({
typing: true,
text: 'Hey there! Would you like to order?',
quick_replies: [
{
content_type: 'text',
title: 'Yes',
payload: 'Y'
},
{
content_type: 'text',
title: 'No',
payload: 'N'
}
],
}) ,
'#askLocation': data => ({
typing: true,
text: 'Please click this button for me to know where you are!',
quick_replies: [
{
content_type: 'location',
title: 'location',
payload: 'location'
}
],
})
}
Can you help me?
I don't know how to add reactions as like\dislike to any message in my telegram bot with written by Node.JS
The problem is I don't know how to change query.message.message_id because message_id every time is different on other chats.
How to count like\dislike I don't know yet too.
Can someone explain to me how to do it well?
Thanks
bot.on('callback_query', query => {
const chatID = query.message.chat.id
switch (query.data) {
case 'good':
console.log(query)
User.find({}).then(users => {
for(var i=0; i < users.length; i++){
var pars = users[i]
bot.editMessageReplyMarkup({
inline_keyboard: [
[
{
text: '👍1',
callback_data: 'good'
},
{
text: '👎',
callback_data: 'bad'
}
]
]
}, {chat_id: pars.telegramId, message_id: query.message.message_id}).catch(e => console.log(e))
}
})
break
case 'bad':
break
}
})
Here for you: 😉
const helpKeyboard = [[{
text: `back`,
callback_data: `back3`
}]]
bot.on('callback_query', msg => {
if (msg.data == `back3`) {
bot.editMessageText(`?`, {
parse_mode: 'Markdown',
message_id: msg.message.message_id,
chat_id: msg.message.chat.id,
reply_markup: {
inline_keyboard: [[{
text: `🔙`,
callback_data: `?`
}]]
}
})
}
}