# Buggy code
def _fill_template(
    self,
    template: Dict[Text, Any],
    filled_slots: Optional[Dict[Text, Any]] = None,
    **kwargs: Any,
) -> Dict[Text, Any]:
    """ "Combine slot values and key word arguments to fill templates."""

    # Getting the slot values in the template variables
    template_vars = self._template_variables(filled_slots, kwargs)

    keys_to_interpolate = [
        "text",
        "image",
        "custom",
        "button",
        "attachment",
        "quick_replies",
    ]
    if template_vars:
        for key in keys_to_interpolate:
            if key in template:
                template[key] = interpolate(template[key], template_vars)
    return template


# Traceback (TypeError)
Encountered an exception while running action 'utter_sifre'. Bot will continue, but the actions events are lost. Please check the logs of your action server for more information.
2020-03-20 07:37:14 DEBUG    rasa.core.processor  - expected string or bytes-like object
Traceback (most recent call last):
File "/build/lib/python3.6/site-packages/rasa/core/processor.py", line 564, in _run_action
events = await action.run(output_channel, nlg, tracker, self.domain)
File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
return self.gen.send(None)
File "/build/lib/python3.6/site-packages/rasa/core/actions/action.py", line 253, in run
message = await nlg.generate(self.template_name, tracker, output_channel.name())
File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 110, in __next__
return self.gen.send(None)
File "/build/lib/python3.6/site-packages/rasa/core/nlg/template.py", line 77, in generate
template_name, filled_slots, output_channel, **kwargs
File "/build/lib/python3.6/site-packages/rasa/core/nlg/template.py", line 93, in generate_from_slots
return self._fill_template(r, filled_slots, **kwargs)
File "/build/lib/python3.6/site-packages/rasa/core/nlg/template.py", line 119, in _fill_template
template[key] = interpolate(template[key], template_vars)
File "/build/lib/python3.6/site-packages/rasa/core/nlg/interpolator.py", line 51, in interpolate
template[k] = [interpolate(i, values) for i in v]
File "/build/lib/python3.6/site-packages/rasa/core/nlg/interpolator.py", line 51, in <listcomp>
template[k] = [interpolate(i, values) for i in v]
File "/build/lib/python3.6/site-packages/rasa/core/nlg/interpolator.py", line 53, in interpolate
template[k] = interpolate_text(v, values)
File "/build/lib/python3.6/site-packages/rasa/core/nlg/interpolator.py", line 17, in interpolate_text
text = re.sub(r"{([^\n{}]+?)}", r"{0[\1]}", template)
File "/usr/local/lib/python3.6/re.py", line 191, in sub
return _compile(pattern, flags).sub(repl, string, count)
TypeError: expected string or bytes-like object
2020-03-20 07:37:14 DEBUG    rasa.core.processor  - Action 'utter_sifre' ended with events '[]'.

# Fixed code
def _fill_template(
    self,
    template: Dict[Text, Any],
    filled_slots: Optional[Dict[Text, Any]] = None,
    **kwargs: Any,
) -> Dict[Text, Any]:
    """ "Combine slot values and key word arguments to fill templates."""

    # Getting the slot values in the template variables
    template_vars = self._template_variables(filled_slots, kwargs)

    keys_to_interpolate = [
        "text",
        "image",
        "custom",
        "button",
        "attachment",
        "quick_replies",
    ]
    if template_vars:
        for key in keys_to_interpolate:
            if key in template:
                template[key] = interpolator.interpolate(template[key], template_vars)
    return template